Home » SQL & PL/SQL » SQL & PL/SQL » SELECT with variables
SELECT with variables [message #36018] Tue, 30 October 2001 06:33 Go to next message
Steve Laliberte
Messages: 1
Registered: October 2001
Junior Member
I don't know if this can be done but i want to perform a SELECT where the field name and the table name are stored in variables.

Exemple :

xTableName VARCHAR2(25);
xFieldName VARCHAR2(7);
xValue VARCHAR2(15);

SELECT xFieldName INTO xValue FROM xTableName

Can this be done ? and how ?

I get errors when i compile.

Thanks !!

----------------------------------------------------------------------
Re: SELECT with variables [message #36023 is a reply to message #36018] Tue, 30 October 2001 07:19 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
If you are running 8i or later, you can use dynamic native SQL (otherwise you'll need to use DBMS_SQL).

execute immediate 'select ' || xFieldName || ' from ' || xTableName into xValue;

----------------------------------------------------------------------
Previous Topic: date format
Next Topic: execute immediate issue - updated
Goto Forum:
  


Current Time: Wed Dec 25 10:50:26 CST 2024