Home » SQL & PL/SQL » SQL & PL/SQL » How to refer to fields in a dynamic multi-row SELECT query?
How to refer to fields in a dynamic multi-row SELECT query? [message #38161] Tue, 26 March 2002 07:46 Go to next message
MarcoC
Messages: 10
Registered: February 2002
Junior Member
Hi all,

I am on orable 8i and I'd like to get the values of any fields specified in the select statement of a dynamic query. The procedure I have would only get me the first field of the select list.
Is there any way to get to all the OTHER fields in the list?

Example:

When stmt is equal to 'select id,first_name from students' "field_val" holds only the "id" values.
When stmt is equal to 'select first_name,id from students' "field_val" holds only the "first_name" values.
When stmt is equal to 'select * from students' "field_val" holds only the "id" values, since "id" is the first field in the table.
How can I refer to the other fields? Thanks. Marco

Here's the code:

CREATE OR REPLACE PROCEDURE showcol (stmt IN VARCHAR2)
IS
TYPE cur_type IS REF CURSOR;
cur cur_type;
field_val VARCHAR2(32767);
BEGIN

OPEN cv FOR
stmt;

LOOP
FETCH cur INTO field_val;
EXIT WHEN cur%NOTFOUND;

DBMS_OUTPUT.PUT_LINE (field_val);
END LOOP;

CLOSE cur;
END;
/
Re: How to refer to fields in a dynamic multi-row SELECT query? [message #38171 is a reply to message #38161] Wed, 27 March 2002 07:18 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
I think that only DBMS_SQL has the functionality to describe the columns of a dynamic query. Search for DBMS_SQL.DESCRIBE_COLUMNS
Previous Topic: oracle query
Next Topic: Calling Perl function within ORACLE PL-SQL statement
Goto Forum:
  


Current Time: Fri Apr 26 13:05:01 CDT 2024