首页 > 代码库 > Oralce生成前N年的年数据

Oralce生成前N年的年数据

今天做一个统计报表的时候正好碰到这个问题,原来,一般是通过后台代码来生成。现在直接通过oracle来生成,记录一下。

方法一:
SELECT YEAR FROM ( SELECT TO_CHAR(SYSDATE-ROWNUM*365,YYYY) YEAR FROM DUAL CONNECT BY ROWNUM<65 UNION SELECT TO_CHAR(SYSDATE,YYYY) YEAR FROM DUAL)ORDER BY YEAR DESC;方法二:SELECT YEAR FROM ( SELECT TO_CHAR(SYSDATE-ROWNUM*365,YYYY) YEAR FROM DUAL CONNECT BY LEVEL<10 UNION SELECT TO_CHAR(SYSDATE,YYYY) YEAR FROM DUAL)ORDER BY YEAR DESC;

 

Oralce生成前N年的年数据