Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Stored Procedures Returning Resultsets
bruce_at_peergroup.com wrote:
>
> I'm looking for a way to to return recordsets using stored procedures
> and ODBC with an Oracle 7.x server. I haven't been able to find any
> examples of this anywhere.
>
> Any help would be appreciated.
>
> Thanks
>
> -----------------------------------------------------------------------
> Bruce Scanlan | bruce_at_peergroup.com
> Systems Integrator | 519 749 9554
> The PEER Group Inc |
Hi Bruce,
see what Thomas Kyte an oracle US employee posted me:
n short, it'll look like this:
create or replace function sp_ListEmp return types.cursortype as
l_cursor types.cursorType;
begin
open l_cursor for select ename, empno from emp order by ename;
return l_cursor;
end;
/
With 7.2 on up 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 an example:
create or replace package types
as
type cursorType is ref cursor;
end;
/
create or replace function sp_ListEmp return types.cursortype as
l_cursor types.cursorType;
begin
open l_cursor for select ename, empno from emp order by ename;
return l_cursor;
end;
/
REM SQL*Plus commands to use a cursor variable
variable c refcursor
exec :c := sp_ListEmp
print c
and the Pro*c to use this would look like:
static void process()
{
EXEC SQL BEGIN DECLARE SECTION;
SQL_CURSOR my_cursor;
VARCHAR ename[40]; int empno;
EXEC SQL ALLOCATE :my_cursor;
EXEC SQL EXECUTE BEGIN
:my_cursor := sp_listEmp;
END; END-EXEC;
for( ;; )
{
EXEC SQL WHENEVER NOTFOUND DO break; EXEC SQL FETCH :my_cursor INTO :ename, empno; printf( "'%.*s', %d\n", ename.len, ename.arr, empno );}
Hope this gives you a hint what to do.
-- Regards Matthias Gresz :-)Received on Fri Nov 28 1997 - 00:00:00 CST
![]() |
![]() |