Oralce生成前N年的年数据
2015-01-12 15:06 Yang-Onion 阅读(292) 评论(0) 编辑 收藏 举报今天做一个统计报表的时候正好碰到这个问题,原来,一般是通过后台代码来生成。现在直接通过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;