Solved

Procedure returning dynamic ref cursor

Posted on 2003-11-08
4
373 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now