1.Oracle中使用connect by 来实现树状查询,其中可以使用level这个伪列来实现分层查询。
2.配合dual表,生成可以计算的连续的值
select .., lever, ..
from dual
connect by lever<= 深度值
利用递归生成20180101到20221231,日期的年季月数据列
SELECT TO_DATE(20180101, 'YYYYMMDD') + LEVEL - 1 AS DAY_CODE,
TO_CHAR(TO_DATE(20180101, 'YYYYMMDD') + LEVEL - 1, 'yyyy-MM') AS MONTH_CODE,
TO_CHAR(TO_DATE(20180101, 'YYYYMMDD') + LEVEL - 1, 'q') AS QUARTER_CODE,
TO_CHAR(TO_DATE(20180101, 'YYYYMMDD') + LEVEL - 1, 'YYYY') AS YEAR_CODE
FROM DUAL
CONNECT BY LEVEL <=
(TRUNC(TO_DATE(20221231, 'YYYYMMDD') -
TRUNC(TO_DATE(20180101, 'YYYYMMDD')) + 1));