Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Is it possible to return recordset from oracle stored procedure ?
On Thu, 02 Oct 1997 22:09:57 -0400, Fenella Tan <fenella_at_voicenet.com> wrote:
>VB cannot retrieve data from an Oracle stored procedure if you are using ODBC
>to connect the client. I only work from the PL/SQL side, and as far as I know
>from my co-workers who do the programs in VB, you can use Oracle OLE to
>retrieve data from stored procedures, but its not possible if you use an ODBC
>connection. We had to resort to populating "temporary" tables.
>
With 7.2 and 7.3 of the database you have cursor variables. Cursor variables are cursors opened by a pl/sql routine and fetched from by another application or pl/sql routine (in 7.3 pl/sql routines can fetch from cursor variables as well as open them). The cursor variables are opened with the privelegs of the owner of the procedure and behave just like they were completely contained within the pl/sql routine. It uses the inputs to decide what database it will run a query on.
Here is a 7.2 / 7.3 example in SQL*Plus and PRO*C
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 EXEC SQL EXECUTE BEGIN empCurType.open_cursor( :my_cursor, 10 ); end; REM END-EXEC; REM 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;
Also, The beta version of Microsoft's latest Oracle ODBC driver (v2.0) is available at: http://www.microsoft.com/msdownload/rds/rdsdownload.htm. It is part of the RDS Server 1.5 Beta download. When you download it you have the option to install any of the included components (ADO, OLE DB, the Oracle ODBC driver, etc...).
Some of the features of the new driver are:
.....
- It can return a resultset from a stored procedure.
.....
>Vjacheslav Saiko wrote:
>
>> Calling programm may be Delphi, or VB.
>> The task is to create stored procedure, which may return recordset to
>> client;
>> i can't find in oracle documenttion , how to do it.
>>
>> Thanks !
>>
>> Fenella Tan wrote:
>>
>> > Oracle PL/SQL stored procedures can return user-defined records and also
>> > rowtypes. Where will you be returning the data to ? Is the calling
>> > program also an Oracle stored procedure ?
>> >
>> > Vjacheslav Saiko wrote:
>> >
>> > > Hi all !
>> > >
>> > > Is it possible to return recordset from oracle stored procedure ?
>> > > Something like :
>> > >
>> > > "select ID,NAME from TABLE1 "
>> > >
>> > > inside stored procedure ...
>> > >
>> > > Thanks for help.
>
>
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Bethesda MD
http://govt.us.oracle.com/ -- downloadable utilities
![]() |
![]() |