最近項目中的查詢模組中,查詢條件用到了年月日下拉框,預設下拉框中都要填充資料,分別是年、月、日,並且還要實現級聯要求。這就需要根據不同的年填充月份資料,不同的月填充不同的日,填充的資料需要查詢陳述式完成。通過努力終於實現了想要的結果,如下:
1.年份:
select (1 - level +to_char(sysdate, 'yyyy')) years from dualconnect by level <=10
2.月份:
SELECT CASE WHEN mons<10 THEN '0'||mons ELSE to_char(mons) END monsNew FROM(select(1 - level + decode(to_char(sysdate, 'yyyy'),'?年份', --參數,本年只填充當前月份以前的時間to_char(sysdate, 'MM'),12)) mons from dualconnect by level <= decode(to_char(sysdate, 'yyyy'),'?年份',to_char(sysdate, 'MM'),12))
3.日期:
SELECT CASE WHEN days<10 THEN '0'||days ELSE to_char(days) END daysNew FROM(select (1 - level + decode(to_char(sysdate, 'yyyy'),'?年份',decode(to_char(sysdate, 'MM'),'?月份', to_number(to_char(sysdate, 'dd')),to_number(to_char(last_day(to_date('?年份?月份'','yyyyMM')),'dd'))),to_number(to_char(last_day(to_date('?年份?月份'','yyyyMM')),'dd')))) days from dualconnect by level <= decode(to_char(sysdate, 'yyyy'),'?年份',decode(to_char(sysdate, 'MM'),'08', to_number(to_char(sysdate, 'dd')),to_number(to_char(last_day(to_date('?年份?月份','yyyyMM')),'dd'))),to_number(to_char(last_day(to_date('?年份?月份'','yyyyMM')),'dd'))))
感覺這語句還是非常用得著的,如果大家還有其它好的語句,希望能拿出來分享~~~