ROW GENERATOR

ROW GENERATOR

SELECT LEVEL just_a_column

FROM dual

CONNECT BY LEVEL <= 365

The theory behind this is that you connect a row to every row of a level higher by omitting the PRIOR keyword. You have no restriction on joining children to parent rows. And if we omit the START WITH clause too, we indicate that ALL records occur at level 1. With a table of one row this means the following: one record (in fact all records) at root level (level 1) because we have no START WITH clause. And at each iteration your hierarchical tree gets deeper (and the LEVEL pseudo column increases) because you match all records of the table to all records of the level above. We stop the recursive hierarchy creation by our constraint. At LEVEL 366 the condition isn’t matched anymore and the query exits its recursive loop.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s