?
Solved

Procedure returning dynamic ref cursor

Posted on 2003-11-08
4
Medium Priority
?
390 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
2 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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 video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

840 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