Run Stored Procedure in SQL Developer? Run Stored Procedure in SQL Developer? oracle oracle

Run Stored Procedure in SQL Developer?


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 parametersprint :OutParam1;print :OutParam2;print :OutParam3;print :OutParam4;


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;


For those using SqlDeveloper 3+, in case you missed that:

SqlDeveloper has feature to execute stored proc/function directly, and output are displayed in a easy-to-read manner.

Just right click on the package/stored proc/ stored function, Click on Run and choose target to be the proc/func you want to execute, SqlDeveloper will generate the code snippet to execute (so that you can put your input parameters). Once executed, output parameters are displayed in lower half of the dialog box, and it even have built-in support for ref cursor: result of cursor will be displayed as a separate output tab.