Home » SQL & PL/SQL » SQL & PL/SQL » Embedded SELECT statements (Oracle 10g, AIX)
Embedded SELECT statements [message #359290] Fri, 14 November 2008 10:18 Go to next message
mounir
Messages: 10
Registered: August 2008
Location: Paris
Junior Member
Hi all,

I have an SQL question about how to use the result of a select statement in order to specify the table from which to retrieve data in another select statement. Here is an example:

Suppose we have a table called TABLE_1 filled as follows:

| ID | TABLE_NAME |
--------------------
| 1 | TEST_2 |
| 2 | TEST_3 |
--------------------

I'd like to write a command that would retrieve the content of the table whose ID is 1 in TABLE_1 (i.e table TEST_2).

The SQL command would be:
 SELECT * FROM (SELECT TABLE_NAME FROM TABLE_1 WHERE ID=1);


This command doesn't work for me. Is there any other solution to solve this problem ?
Re: Embedded SELECT statements [message #359293 is a reply to message #359290] Fri, 14 November 2008 10:35 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
This has been asked several times here.
You can't do it unless you use dynamic SQL.

Regards
Michel
Re: Embedded SELECT statements [message #359649 is a reply to message #359290] Mon, 17 November 2008 19:28 Go to previous message
wmgonzalbo
Messages: 98
Registered: November 2008
Member
Had a quick test on this using Execute Immediate, cant seem to make it work..

Michel C. is right, you have to use a dynamic query. I have done this before (also with Michel's suggestion), trydbms_sql.

Regards,
Wilbert
Previous Topic: where condition based on column value
Next Topic: Select Rows as Columns
Goto Forum:
  


Current Time: Thu Dec 08 08:51:40 CST 2016

Total time taken to generate the page: 0.09550 seconds