Solved

Procedure returning dynamic ref cursor

Posted on 2003-11-08
4
378 Views
Last Modified: 2012-06-27
Hi,

I am having a procedure which returns refcursor as a out parameter. This ref cursor has to be build dynamically inside my procedure based on two in parameters to the procedure. These in parameters decide what would be the "WHERE" condition for my return cursor. This procedure is being called through a VB bas file which reads the cursor for the values returned.

1) The dbms_sql package works with cursor id/number. But I need to refer to this cursor with cursor name. Can this be done?
2) I need to dynamically parse the cursor and return it as an out parameter from the procedure instead of executing.

The dynamic SQL referenced by the cursor is a SELECT statement returning multiple rows.

Is my approach appropriate? Is there any other way of doing this?

Thanks in advance,
Pankaj







0
Comment
Question by:Pankaj27
4 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 70 total points
ID: 9709553
You don't want DBMS_SQL for this.  Your procedure should be more like this:

PROCEDURE p ( p_where IN VARCHAR2, p_rc IN OUT SYS_REFCURSOR ) IS
  v_sql VARCHAR2(32767);
BEGIN
  v_sql := 'SELECT * FROM EMP WHERE ' || p_where;
  OPEN p_rc FOR v_sql;
END;
0
 

Expert Comment

by:ryanjmw
ID: 10599679
hi, but then, another problem arise ==>> ORU-10028!
when I place the long string into the string-variable v_sql.

how i can handle this?

use dbms_output? how to pass the PL/SQL table parameter (from dbms_output ) to the OPEN-CURSOR statement, will it work ?

pls help ! thx.
Ryan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question