Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Using bind vars, ref cursors and dynamic SQL

Re: Using bind vars, ref cursors and dynamic SQL

From: Daniel Morgan <damorgan_at_exxesolutions.com>
Date: Wed, 02 Jul 2003 08:51:29 -0700
Message-ID: <3F02FF81.D4C8C458@exxesolutions.com>


Mark wrote:

> Hello,
>
> I'm trying to return values from my database using ref cursors, dynamic SQL
> and bind variables, but I cannot seem to get the syntax right.
>
> It looks like this currently:
>
> /*
> rec_services is declared thusly: TYPE rec_services IS REF CURSOR;
> */
> FUNCTION my_function
> (pv_param1 IN VARCHAR2
> ,pv_param2 IN VARCHAR2
> )
> RETURN rec_services
> IS
> vr_service rec_services;
> BEGIN
>
> /*
> pv_param1 contains 'LIKE (..., ..., ...)'
> */
> EXECUTE IMMEDIATE
> 'DECLARE '||
> 'CURSOR cur_records IS '||
> 'SELECT ss.col1'||
> ', ss.col2'||
> 'FROM my_view ss '||
> 'WHERE ss.col1 :b1 '||
> 'AND ss.col2 = :b2 '||
> 'ORDER BY ss.col1;'||
> 'BEGIN '||
> 'OPEN cur_records;'||
> 'FETCH cur_records '||
> 'INTO :b3'||
> ', :b4;'||
> 'CLOSE cur_records;'||
> 'END;'
> USING IN pv_param1
> , IN pv_param2
> , OUT vr_service.col1
> , OUT vr_service.col2
> ;
>
> RETURN vr_service;
>
> END my_function;
>
> The error I am getting is:
>
> PLS-00487: Invalid reference to variable 'VR_SERVICE'
>
> Thanks for any assistance,
>
> Mark

Assuming 8i try this:

CREATE OR REPLACE PROCEDURE child (
  p_NumRecs IN PLS_INTEGER,
  p_return_cur OUT uw_type.t_ref_cursor) IS

BEGIN
   OPEN p_return_cur FOR
   'SELECT * FROM all_tables WHERE rownum <= ' || p_NumRecs ;

END child;
/

Assuming 9i try this:

CREATE OR REPLACE PROCEDURE child (
  p_NumRecs IN PLS_INTEGER,
  p_return_cur OUT SYS_REFCURSOR)
IS

BEGIN
   OPEN p_return_cur FOR
   'SELECT * FROM all_tables WHERE rownum <= ' || p_NumRecs ;

END child;
/

I think you've overcomplicated things a bit.

--
Daniel Morgan
http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp
damorgan_at_x.washington.edu
(replace 'x' with a 'u' to reply)
Received on Wed Jul 02 2003 - 10:51:29 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US