Friday, May 23, 2008

Generate A SQL Query

This query will generate the code for a second query that will look at tables with 'EMP' in the name and compile all the source code from User_Source. In this case, the last 'UNION' would be manually removed before running.
Select
'Select Name, Text ' ||
'From User_Source ' ||
'Where Upper(Text) Like ' ||
'''%'||Table_Name||'%'' ' ||
'Union '
As
New_Query
From User_Tables
Where Table_Name Like '%EMP%';

New_Query
------------------------------------------------------------------------
Select Name, Text From User_Source Where Text Like '%Emp%' Union
Select Name, Text From User_Source Where Text Like '%Inc_Empls%' Union

No comments:

Post a Comment