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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT in FROM clause not working

Status
Not open for further replies.

lbrechler

Programmer
May 17, 2001
44
US
Hi.

I need to perform the following query:

SELECT * from (SELECT s.tablename FROM sourcedef s, attriblist a WHERE a.attribid=1 and a.sourceid = s.sourcedefid)

In both Toad and SQL*Plus, this is returning the value of the table name only, i.e. the results of the inner query.

Is the SQL formatted correctly? Any suggestions?

Thanks.
~Lindsay
 
Hi,
Your query asks for all fields returned by the sub-query: The sub-query returns s.tablename and nothing else:
All is working exactly as you requested...

What do you really want to return?

[profile]
 
Well, I want all rows/columns of the table whose name is stored in sourcedef. So I need to select sourcedef.tablename, and use the resulting value (let's say it's "mytablename") to do "select * from mytablename"...
 
HI,

You need to use dynamic SQL for your type of query using a PL/SQL block.

Regards
lionofthejungle
 
You could also run a script from sql plus
set pagesize 0
set linesize 120

Spool runme.sql
SELECT distinct 'Select * from '||s.tablename ||';'
FROM sourcedef s, attriblist a
WHERE a.attribid=1 and a.sourceid = s.sourcedefid
/
Spool Off
Spool Myresult.txt
@runme.sql
spool off
ed Myresult.txt

Did this very fast. Please check Syntax for what you need.
Vinnie


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top