I am looking for a reliable algorithmic way to nest queries in Oracle without having to parse and rebuild SQL statements. In DB2, MYSQL, and SQLITE I can simply nest from the largest columns set in the inner subquery to the smallest column set in the very outer query like this:
SELECT A, B FROM (
SELECT A, B, C FROM (
SELECT A, B, C, D FROM (
SELECT * FROM myTable
)
)
)
)
This does not work for Oracle, I had to use the WITH clause but that allows me one level of nesting like
WITH Q1 as (
SELECT * FROM myTable
)
SELECT A, B FROM Q1
is there an algorithmic way to nest select statements in Oracle like DB2 or MySQL above
You can always assume it is a single table. The queries are generated automatically
Found the root cause:
My code assumes an "AS alias" is needed and appends it to the subquery as in "Select A, B from (select A, B, C from myTable) AS Q1" --- Oracle does not like that and gives an error "missing right parenthesis"