views:

75

answers:

4

Hi,

I am trying to run a stored procedure that has multiple in and out paramaters. The procedure can only be viewed in my Connections panel by navigating Other Users | | Packages | |

If I right click , the menu items are "Order Members By..." and "Create Unit Test" (greyed out). The ability to "Run" the procedure does not seem possible when it's accessed by user.

I have been trying to find an example of how to create an anonymous block so that I can run the procedure as a SQL file, but haven't found anything that works.

Does anyone know how I can execute this procedure from SQL Developer? I am using Version 2.1.1.64.

Thanks in advance!

EDIT 1:

The procedure I want to call has this signature:

user.package.procedure(
   p_1 IN  NUMBER,
   p_2 IN  NUMBER,
   p_3 OUT VARCHAR2,
   p_4 OUT VARCHAR2,
   p_5 OUT VARCHAR2,
   p_6 OUT NUMBER)

If I write my anonymous block like this:

DECLARE
   out1 VARCHAR2(100);
   out2 VARCHAR2(100);
   out3 VARCHAR2(100);
   out4 NUMBER(100);
BEGIN
   EXECUTE user.package.procedure (33,89, :out1, :out2, :out3, :out4);
END;

I get the error:

Bind Varialbe "out1" is NOT DECLCARED
anonymous block completed

I've tried initializing the out* variables:

   out1 VARCHAR2(100) := '';

but get the same error:

EDIT 2:

Based on Alex's answer, I tried removing the colons from in front of the params and get this:

Error starting at line 1 in command:
DECLARE
   out1 VARCHAR2(100);
   out2 VARCHAR2(100);
   out3 VARCHAR2(100);
   out4 NUMBER(100);
BEGIN
   EXECUTE user.package.procedure (33,89, out1, out2, out3, out4);
END;
Error report:
ORA-06550: line 13, column 17:
PLS-00103: Encountered the symbol "USER" when expecting one of the following:

   := . ( @ % ; immediate
The symbol ":=" was substituted for "USER" to continue.
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
A: 

While it's the TSQL way that I would do it, why not do something like this in a new script window? Does ORA not let you?

DECLARE @OUTparam1 INT
DECLARE @OUTparam2 INT
DECLARE @INparam1 INT
DECLARE @INparam2 INT

SET @INparam1 = 1
SET @INparam2 = 0

EXEC MySprocThatIsHard @INparam1, @INparam2, @OUTparam1, @OUTparam2
drachenstern
That won't work
Conrad Frix
Thanks for the helpful and explanatory comment @Conrad Frix ... care to elaborate? I realize I'm not an ORA guy and never will be (if I can help it) but I didn't think that SQL made it hard to run procedures.
drachenstern
@drachenstern Sorry, I didn't mean to be terse. But ORA's Goofy Syntax is really different.
Conrad Frix
@Conrad Frix ~ That's cool. So anyways the difference appears to be syntax on how to run it. How do you use a dynamic variable for an input value in your query example? As in my pseudo example where I use `@INparam1` ... or would it not allow you to do that?
drachenstern
Alex Poole
+1  A: 

Executing easy. Getting the results can be hard.

Take a look at this question I asked Best way/tool to get the results from an oracle package procedure

The summary of it goes like this.

Assuming you had a Package named mypackage and procedure called getQuestions. It returns a refcursor and takes in string user name.

All you have to do is create new SQL File (file new). Set the connection and paste in the following and execute.

var r refcursor;
exec mypackage.getquestions(:r, 'OMG Ponies');
print r;
Conrad Frix
+1  A: 

Use:

BEGIN

  PACKAGE_NAME.PROCEDURE_NAME(parameter_value, ...);

END;

Replace "PACKAGE_NAME", "PROCEDURE_NAME", and "parameter_value" with what you need. OUT parameters will need to be declared prior to.

OMG Ponies
+2  A: 

With simple parameter types (i.e. not refcursors etc.) you can do something like this:

SET serveroutput on;
DECLARE
    InParam1 number;
    InParam2 number;
    OutParam1 varchar2(100);
    OutParam2 varchar2(100);
    OutParam3 varchar2(100);
    OutParam4 number;
BEGIN
    /* Assign values to IN parameters */
    InParam1 := 33;
    InParam2 := 89;

    /* Call procedure within package, identifying schema if necessary */
    schema.package.procedure(InParam1, InParam2,
        OutParam1, OutParam2, OutParam3, OutParam4);

    /* Display OUT parameters */
    dbms_output.put_line('OutParam1: ' || OutParam1);
    dbms_output.put_line('OutParam2: ' || OutParam2);
    dbms_output.put_line('OutParam3: ' || OutParam3);
    dbms_output.put_line('OutParam4: ' || OutParam4);
END;
/


Edited to use the OP's spec, and with an alternative approach to utilise :var bind variables:

var InParam1 number;
var InParam2 number;
var OutParam1 varchar2(100);
var OutParam2 varchar2(100);
var OutParam3 varchar2(100);
var OutParam4 number;

BEGIN
    /* Assign values to IN parameters */
    :InParam1 := 33;
    :InParam2 := 89;

    /* Call procedure within package, identifying schema if necessary */
    schema.package.procedure(:InParam1, :InParam2,
        :OutParam1, :OutParam2, :OutParam3, :OutParam4);
END;
/

-- Display OUT parameters
print :OutParam1;
print :OutParam2;
print :OutParam3;
print :OutParam4;
Alex Poole
+1 nice answer. Out of curiosity do you know which is preferred?
Conrad Frix
@Conrad: I imagine it's a preference thing, though there might be more context switching the `:var` way. I'd use the `declare` way by default if I was doing anything with PL/SQL; but I might use `:var` if, say, I was using a bit of existing code copied in from Pro*C which already had that syntax and I didn't want to touch the parms in the call.
Alex Poole
Thanks for the help and the detailed answer. I'm sure it will be a help to others as well. One thing to note is that these must be run as scripts not statements.
sdoca