近30天
-- 近30天 SELECT to_char(day,'yyyy-mm-dd') as "days" from ( SELECT to_date(to_char(trunc(to_date('2021-09-30','yyyy-MM-dd'), 'dd'), 'yyyy-mm-dd'), 'yyyy-mm-dd') - rownum + 1 as day FROM dual CONNECT BY ROWNUM <= 30 ) ORDER BY day asc
近5年
-- 近5年 SELECT to_char(SYSDATE,'YYYY') - LEVEL + 1 as "xAxisValue" FROM dual CONNECT BY LEVEL <= 5 ORDER BY to_char(SYSDATE,'YYYY') - LEVEL + 1 ASC
近6个月
-- 根据当前时间获取最近6个月时间(yyyy-mm): SELECT TO_CHAR(add_months(to_date(to_char(trunc(sysdate, 'mm')+1, 'yyyy-mm'), 'yyyy-mm'), -(ROWNUM - 1)), 'yyyy-mm') as "xAxisValue" FROM dual CONNECT BY ROWNUM <= 6 ORDER BY TO_CHAR(add_months(to_date(to_char(trunc(sysdate, 'mm')+1, 'yyyy-mm'), 'yyyy-mm'), -(ROWNUM - 1)), 'yyyy-mm') ASC
日期区间的天数
SELECT to_char(day, 'yyyy-mm-dd') as "xAxisValue" from ( SELECT to_date(to_char(trunc(to_date('2021-07-10', 'yyyy-mm-dd'), 'dd'), 'yyyy-mm-dd'), 'yyyy-mm-dd') - rownum + 1 as day FROM dual CONNECT BY ROWNUM <= (to_date('2021-07-10', 'yyyy-mm-dd') - to_date('2021-06-10', 'yyyy-mm-dd') + 1) ) ORDER BY day asc