WITH t(n) AS (
SELECT '2009-10-08' from dual
UNION ALL
SELECT TO_CHAR(to_date(n,'yyyy-mm-dd') + (INTERVAL '1' DAY), 'yyyy-mm-dd' ) FROM t WHERE n > '2009-10-05'
)
SELECT * FROM t;
用'-'替换'+',此查询的结果完全不变。
这怎么可能发生?
查询结果是
2009-10-08
2009-10-07
2009-10-06
2009-10-05
答案 0 :(得分:2)
您可以简化此操作,因为您可以直接使用日期:
WITH t(n) AS (
SELECT date '2009-10-08' from dual
UNION ALL
SELECT n - 1
FROM t
WHERE n > date '2009-10-05'
)
SELECT to_char(n, 'yyyy-mm-dd') as n
FROM t;
返回:
N
----------
2009-10-08
2009-10-07
2009-10-06
2009-10-05
关于在递归CTE中使用DATE(或TIMESTAMP)算法存在一些错误。上面的内容对我来说使用Oracle 12.2.0.1和11.2.0.3