PL/SQL - Use bind variable in "from <table>" query

  • From: Lyndon Tiu <ltiu@xxxxxxxxxxxxx>
  • To: oracle-l <oracle-l@xxxxxxxxxxxxx>
  • Date: Mon, 31 Jan 2005 21:05:06 -0800

Hello,

I have a lookup table with a column.

This column holds a variable - the name of another table.

In PL/SQL code, I need to query (at run time) the lookup table, retrieve the 
value stored in the lookup table's column and use it as the table in another 
query.

I have tried using bind variables but it seems that I cannot set the <table> 
in:

select * from <table>

to a bind variable.

The code:

------------
declare:

v_table_name  varchar2

v_value  varchar2

begin

select  table_name  into  v_table_name  from  lookup_table;

select  value into v_value  from  :v_table_name;

end;
------------

does not even compile. I get an error that :v_table_name is a bad bind 
variable.

Thanks for any help.

--
Lyndon Tiu
--
//www.freelists.org/webpage/oracle-l

Other related posts: