Solved

Procedure returning dynamic ref cursor

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

Independent Software Vendors: 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

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…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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 copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

726 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