How to get rows N times in a result set? [message #446567] |
Tue, 09 March 2010 06:15  |
terber
Messages: 1 Registered: March 2010
|
Junior Member |
|
|
How to get rows N times in a result set?
For obscure test purposes I need to modify an existing SQL query to emit the rows N times instead once.
I'm aware of the possibility to "UNION ALL" the query with itself to get the all rows twice.
But as I require the resulting rows to be emitted around ten to hundred times this approach doesn't seem sensible to me. Not to speak of the missing possibility to parametrize the number of "repetitions".
How can I achieve my goal?
[Updated on: Tue, 09 March 2010 07:40] by Moderator Report message to a moderator
|
|
|
|
Re: How to get rows N times in a result set? [message #446578 is a reply to message #446571] |
Tue, 09 March 2010 06:35  |
 |
Michel Cadot
Messages: 68737 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Take care this only works with a result set with one row.
Better use:
SQL> select ename, deptno from emp where deptno = 10;
ENAME DEPTNO
---------- ----------
CLARK 10
KING 10
MILLER 10
3 rows selected.
SQL> with lines as (select level line from dual connect by level <= 5)
2 select ename, deptno
3 from emp, lines
4 where deptno = 10
5 /
ENAME DEPTNO
---------- ----------
CLARK 10
KING 10
MILLER 10
CLARK 10
KING 10
MILLER 10
CLARK 10
KING 10
MILLER 10
CLARK 10
KING 10
MILLER 10
CLARK 10
KING 10
MILLER 10
15 rows selected.
Regards
Michel
[Updated on: Tue, 09 March 2010 06:35] Report message to a moderator
|
|
|