Monday, July 21, 2008

Generate numbers 1 to N from a query without any PL/SQL

select rownum from ( select 1 from dual group by cube (1,1,1,1,1,1)) where rownum<&maxlimit+1

The logic behind this query is that, the CUBE is generating 2^n rows where n is the number of arguments to the CUBE function. In this case the inner subquery generates 2^6 rows i.e. 64 rows with value 1 which means you can generate numbers up to 64. If we give 7 1s in the CUBE , then we can generate up to 128. Simply, range can be increased by increasing the number of arguments to the CUBE function.

No comments:

search engine

Custom Search