?
Solved

Procedure returning dynamic ref cursor

Posted on 2003-11-08
4
Medium Priority
?
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 280 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

Technology Partners: 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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

771 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