Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Repeating numbers in a sequence as n=many times as the number

611118Feb 28 2008 — edited Mar 3 2008

I gave myself a small puzzle, to try to get the numbers 1-5 repeating as many times as their values: 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5

My first attempt was quite simple. But i do not understand the results. Can someone explain to me why these are the results?

SQL> SELECT
  2     Rownum,
  3     A
  4  FROM
  5     (SELECT Rownum A FROM Dual CONNECT BY Rownum <= 5)
  6  CONNECT BY
  7     Rownum <= A;

    ROWNUM          A
---------- ----------
         1          1
         2          2
         3          3
         4          4
         5          5
         6          2
         7          3
         8          4
         9          5

9 rows selected.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2008
Added on Feb 28 2008
20 comments
2,062 views