Create N rows on the fly
845940Mar 9 2011 — edited Mar 9 2011I'm looking for a query that creates a number of N records without having a table in the database. I have this done in ms sql server using "union select" to create a static list of rows and then restrict this to N records using "select top N". The query is generated and N is passed as a parameter.
In ms sql it looks like this where <count> is replaced by the number of rows I need (the list can have maximum 1000 rows):
select top <count> a.c n1, b.c n2,c.c n3,d.c n4 from (select '1' as c union select '2' as c union select '3' as c union select '4' as c union select '5' as c union select '6' as c union select '7' as c union select '8' as c ) a, (select '1' as c union select '2' as c union select '3' as c union select '4' as c union select '5' as c union select '6' as c union select '7' as c union select '8' as c ) b, (select '1' as c union select '2' as c union select '3' as c union select '4' as c union select '5' as c union select '6' as c union select '7' as c union select '8' as c ) c, (select '1' as c union select '2' as c ) d
I know this is not a clean solution, but doesn't matter. The content of the list doesn't matter as well. I just need N rows no matter how many columns.
How does this work in pl/sql?