单个SQL查询应显示sysdates如下

时间:2015-05-07 15:10:53

标签: sql oracle

需要输出

Sysdate
Sysdate+1
Sysdate+2
Sysdate+3

它应该类似于以下查询的输出,

SELECT SYSDATE FROM DUAL

UNION

SELECT SYSDATE+1 FROM DUAL

UNION

. . .

. . .

so on,

但不应使用UNION,帮助。

1 个答案:

答案 0 :(得分:2)

您可以使用CONNECT BY

SELECT SYSDATE + LEVEL - 1
FROM   DUAL
CONNECT BY LEVEL <= 4;

或者您可以使用公用表表达式

WITH CTE( "Date", lvl ) AS
(
  SELECT SYSDATE, 1 FROM DUAL
  UNION ALL
  SELECT SYSDATE + lvl, lvl + 1 FROM CTE WHERE lvl <= 3
)
SELECT "Date" FROM CTE;