Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get resultset from oracle stored procedure

I'm working on converting a stored procedure from SQL server to Oracle. This stored procedure provides a direct resultset. I mean that if you call the stored procedure in eg Management Studio you directly obtain the resultset.

By converting to Oracle I walk against the problem that I in Oracle will not display the resultset

I searched on the Internet and have seen that the stored procedure should yield a REF CURSOR, but I still walk with the problem to write a little piece of code to obtain the resultset en process that.

Pseudo Code:

Call stored procedure and obtain cursor Do something with that cursor so that my resultset appears

Someone an idea?

like image 377
jwdehaan Avatar asked Jul 23 '09 09:07

jwdehaan


People also ask

How to return a result set from an Oracle stored procedure?

To return a cursor from an Oracle stored procedure, the output parameter of the procedure must be declared as a cursor type. You must also declare that parameter as a cursor in the LWJDBC adapter. Below is a complete working example utilizing existing pools and a Sterling Integrator table.

Does stored procedure return value in Oracle?

A stored procedure does not have a return value but can optionally take input, output, or input-output parameters. A stored procedure can return output through any output or input-output parameter.

Can Oracle stored procedure return multiple result sets?

To make the migration of other databases to the Oracle Database easier, Oracle Database 12c Release 1 added a new feature called implicit statement result that allows you to return one or more result sets from a stored procedure by using the dbms_sql package.

Is in stored procedure Oracle?

Stored procedures and functions (subprograms) can be compiled and stored in an Oracle Database XE, ready to be executed. Once compiled, it is a schema object known as a stored procedure or stored function, which can be referenced or called any number of times by multiple applications connected to Oracle Database XE.


1 Answers

In SQL Plus:

SQL> create procedure myproc (prc out sys_refcursor)   2  is   3  begin   4     open prc for select * from emp;   5  end;   6  /  Procedure created.  SQL> var rc refcursor SQL> execute myproc(:rc)  PL/SQL procedure successfully completed.  SQL> print rc       EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO ---------- ---------- --------- ---------- ----------- ---------- ---------- ----------       7839 KING       PRESIDENT            17-NOV-1981       4999                    10       7698 BLAKE      MANAGER         7839 01-MAY-1981       2849                    30       7782 CLARKE     MANAGER         7839 09-JUN-1981       2449                    10       7566 JONES      MANAGER         7839 02-APR-1981       2974                    20       7788 SCOTT      ANALYST         7566 09-DEC-1982       2999                    20       7902 FORD       ANALYST         7566 03-DEC-1981       2999                    20       7369 SMITHY     CLERK           7902 17-DEC-1980       9988         11         20       7499 ALLEN      SALESMAN        7698 20-FEB-1981       1599       3009         30       7521 WARDS      SALESMAN        7698 22-FEB-1981       1249        551         30       7654 MARTIN     SALESMAN        7698 28-SEP-1981       1249       1400         30       7844 TURNER     SALESMAN        7698 08-SEP-1981       1499          0         30       7876 ADAMS      CLERK           7788 12-JAN-1983       1099                    20       7900 JAMES      CLERK           7698 03-DEC-1981        949                    30       7934 MILLER     CLERK           7782 23-JAN-1982       1299                    10       6668 Umberto    CLERK           7566 11-JUN-2009      19999          0         10       9567 ALLBRIGHT  ANALYST         7788 02-JUN-2009      76999         24         10 
like image 82
Tony Andrews Avatar answered Sep 18 '22 09:09

Tony Andrews