Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Cursor (REF CURSOR) and Fetch problem...

Status
Not open for further replies.

wellster34

Programmer
Sep 4, 2001
113
CA
Hello,

I have a dynamically created select statement and store it in VARCHAR2 variable. Now, I need to open and execute it to fetch the values.

DECLARE
...
TYPE cv_type IS REF CURSOR;
TEST_CURSOR cv_type;
...
BEGIN
...
OPEN TEST_CURSOR FOR v_select_string;

I'm good to here but I have not figured out to fetch it. I have tried the FOR testing_cur IN TEST_CURSOR LOOP....END LOOP;

I get the PLS-00221: 'TEST_CURSOR' is not a procedure or is undefined


Any suggestions?


The situation I have is that since this is a dynamic sql select statement, I can not hard code the variables so that I could do the FETCH TEST_CURSOR INTO ....


Thanks for your time,
 
You will probably need to build a record that matches the anticipated structure of your cursor:

TYPE my_record_type IS RECORD(col1 VARCHAR2(10),....);
my_record MY_RECORD_TYPE
.
.
.
OPEN TEST_CURSOR FOR v_select_string;
LOOP
FETCH test_cursor INTO my_record;
EXIT WHEN test_cursor%NOTFOUND;
.
.
.
END LOOP;
CLOSE test_cursor;
.
.
.
 
Hi,

Do you know if you can create the TYPE part dynamically? Or is it hardcoded in the DECLARE...

TYPE my_record_type IS RECORD(col1 VARCHAR2(10),....);


My situation is that I can not hard code the TYPE due to the input table can change on the fly?
 
With DBMS_SQL you can use DESCRIBE to work out how many columns you are returning in a dynamic cursor.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top