根据当前时间获取最近5年时间:(yyyy)
SELECT to_char(SYSDATE,’YYYY’) - LEVEL + 1 as “xAxisValue”
FROM dualCONNECT BY LEVEL <= 5
ORDER BY to_char(SYSDATE,’YYYY’) - LEVEL + 1 ASC
根据当前时间获取最近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
根据当前时间获取最近30天时间:
SELECT to_char(day,’yyyy-mm-dd’) as “xAxisValue”
from (
SELECT to_date(to_char(trunc(sysdate, ‘dd’), ‘yyyy-mm-dd’), ‘yyyy-mm-dd’) - rownum + 1 as day
FROM dual
CONNECT BY ROWNUM <= 30
)
ORDER BY day asc
也可根据输入起止时间来获取时间段内的天:如下为获取2017-06-10到2017-07-10时间段内的天(yyyy-mm-dd)
SELECT to_char(day,’yyyy-mm-dd’) as “xAxisValue”
from (
SELECT to_date(to_char(trunc(to_date(‘2017-07-10’, ‘yyyy-mm-dd’), ‘dd’), ‘yyyy-mm-dd’), ‘yyyy-mm-dd’) - rownum + 1 as day
FROM dual
CONNECT BY ROWNUM <= (to_date(‘2017-07-10’, ‘yyyy-mm-dd’) - to_date( ‘2017-06-10’, ‘yyyy-mm-dd’) + 1)
)
ORDER BY day asc
</div>