I'm looking at somebody elses code, and I'm tring to figure out what is going on?
What does the select 1 etc.
unioned with Select 2,1 etc doing?
select 1 order_by1, column_id order_by2,
decode(column_id, 1, 'select ', ' ||') ||
'''"''' || '||' || decode(data_type,
'DATE', 'to_char(') || column_name ||
|| ' || ' || '''",''' text
where table_name = Upper('&tablename')
and data_type != 'LONG'
and owner = Upper('&Owner')
select 2, 1, ' from &tablename'
select 3, 1, '&whereclause;'
order by 1,2;
They're just using a "trick" to make sure that the rows returned from the first query in the statement come before the ones from the second query and before the rows from the third query. It is perfectly valid to specify a literal value in a select statement. BY "tagging" each row from each query with a numeric value, the ORDER BY at the end will ensure that the rows from the first query come first, the rows from the second one next and, finally, the rows from the third.
Click Here to Expand Forum to Full Width