Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Returning rows from a stored procedure - how?
On Tue, 01 Apr 1997 01:57:58 GMT, lsantos_at_pobox.com (Luis Santos) wrote:
>Andy Noble <andy_at_dataworkshop.demon.co.uk> wrote:
>
>> However I cannot find ANY documentation telling me how to
>> return a result set from a SELECT statement back to the
>> front end application. I can only find comments that it is
>> possible.
>
> You haven't found any documentation about result sets in
>functions or storage procedures because IT'S NOT POSSIBLE!
>
> I think that Oracle8 may be capable of doing this (as
>Microsoft SQL Server is...)
>
> There's some ways (no one easy or transparent) to do this. You
>can use a pipe in the storage procedure to send data to application
>program, before the procedure returns. You can write the result set to
>some temporary table and allows the application program to select from
>it and so on...
>
>
> Regards,
>--
>Luis Santos
>Relacional Consultoria
>Rio de Janeiro - Brazil
Starting with 7.2 of the database, there is an easier way to accomplish this called cursor variables. Here is a SQL*Plus and PRO*C example. The procedure open_cursor will return a result set to the client application. The result set it gets will depend on the inputs to the procedure.
create or replace package empCurType
as
cursor c1 is select ename, mgr, dept.deptno, dname, loc from emp, dept;
type empCur is ref cursor return c1%rowtype;
procedure open_cursor( p_cursor in out empCur, p_deptno in number );
create or replace package body empCurType as
procedure open_cursor( p_cursor in out empcur, p_deptno in number )
is
begin
if ( p_deptno in ( 10, 20 ) ) then -- open local query open p_cursor for select ename, mgr, dept.deptno, dname, loc from emp, dept where emp.deptno = dept.deptno and dept.deptno = p_deptno; else open p_cursor for select ename, mgr, dept.deptno, dname, loc from emp_at_aria.world, dept_at_aria.world where emp.deptno = dept.deptno and dept.deptno = p_deptno; end if;
end empCurType;
/
show errors
REM --------------- SQL*Plus using RefCursor to display results ------
variable C refcursor
exec empCurType.open_cursor( :C, 10 )
print C
REM ----------- PRO*C Getting the cursor ------------------REM
REM typedef char asciiz; REM EXEC SQL TYPE asciiz IS STRING(100); REM SQL_CURSOR my_cursor; REM asciiz ename[40]; REM int mgr; REM short mgr_i; REM int deptno; REM asciiz dname[50]; REM asciiz loc[50]; REM int i;
REM for( ;; ) REM { REM EXEC SQL WHENEVER NOTFOUND DO BREAK; REM EXEC SQL FETCH :my_cursor REM INTO :ename, :mgr:mgr_i, :deptno, :dname, :loc; REM REM printf( "%s, %d, %d, %s, %s\n", REM ename, mgr_i?-1:mgr, deptno, dname, loc ); REM } REM EXEC SQL CLOSE :my_cursor;
http://govt.us.oracle.com/ -- downloadable utilities
![]() |
![]() |