Oracle 19c SQL

  1. Home
  2. Docs
  3. Oracle 19c SQL
  4. 8 Hierarchical Query
  5. 8.5 Some more hierarchical queries

8.5 Some more hierarchical queries

If START WITH clause is not mentioned, Oracle can not determine which row is parent. Hence, it takes all rows as parent and derives the hierarchy for each row. So, sometimes the output may look meaningless without a START WITH, but there are situations where START WITH is absolutely not required and with only CONNECT BY clause the output is meaningful.

Q : Generate numbers 1 to 10?

Ans:

SELECT LEVEL Num
  FROM DUAL 
CONNECT BY LEVEL <= 10;

       NUM
----------
	 1
	 2
	 3
	 4
	 5
	 6
	 7
	 8
	 9
        10

10 rows selected.

Q : Display last 7 days dates including today?

Ans:

 SELECT (sysdate - LEVEL) + 1 AS "Week days" 
   FROM DUAL
 CONNECT BY LEVEL <= 7;

Week days
---------
10-MAR-20
09-MAR-20
08-MAR-20
07-MAR-20
06-MAR-20
05-MAR-20
04-MAR-20

7 rows selected.
Was this article helpful to you? Yes No

How can we help?