WITH TEST_TABLE AS ( SELECT '데이타1' CONTENT, '20160101' SDATE, '20160118' EDATE FROM DUAL UNION ALL SELECT '데이타2' CONTENT, '20160101' SDATE, '20160111' EDATE FROM DUAL UNION ALL SELECT '데이타3' CONTENT, '20160112' SDATE, '20160115' EDATE FROM DUAL UNION ALL SELECT '데이타4' CONTENT, '20160114' SDATE, '20160114' EDATE FROM DUAL UNION ALL SELECT '데이타5' CONTENT, '20160114' SDATE, '20160117' EDATE FROM DUAL UNION ALL SELECT '데이타6' CONTENT, '20160112' SDATE, '20160112' EDATE FROM DUAL UNION ALL SELECT '데이타7' CONTENT, '20160111' SDATE, '20160113' EDATE FROM DUAL UNION ALL SELECT '데이타8' CONTENT, '20160114' SDATE, '20160114' EDATE FROM DUAL UNION ALL SELECT '데이타9' CONTENT, '20160113' SDATE, '20160118' EDATE FROM DUAL UNION ALL SELECT '데이타10' CONTENT, '20160101' SDATE, '20160109' EDATE FROM DUAL UNION ALL SELECT '데이타11' CONTENT, '20160117' SDATE, '20160118' EDATE FROM DUAL ) SELECT CONTENT, SDATE , EDATE FROM TEST_TABLE WHERE 1=1 AND (DECODE(TO_CHAR(SYSDATE , 'D') , '1' , TO_CHAR(SYSDATE , 'YYYYMMDD') , TO_CHAR(SYSDATE - TO_CHAR(SYSDATE , 'D')+1 , 'YYYYMMDD') ) BETWEEN SDATE AND EDATE OR DECODE(TO_CHAR(SYSDATE , 'D') , '7' , TO_CHAR(SYSDATE , 'YYYYMMDD') , TO_CHAR(SYSDATE - TO_CHAR(SYSDATE , 'D')+7 , 'YYYYMMDD') ) BETWEEN SDATE AND EDATE OR SDATE BETWEEN DECODE(TO_CHAR(SYSDATE , 'D') , '1' , TO_CHAR(SYSDATE , 'YYYYMMDD') , TO_CHAR(SYSDATE - TO_CHAR(SYSDATE , 'D')+1 , 'YYYYMMDD') ) AND DECODE(TO_CHAR(SYSDATE , 'D') , '7' , TO_CHAR(SYSDATE , 'YYYYMMDD') , TO_CHAR(SYSDATE - TO_CHAR(SYSDATE , 'D')+7 , 'YYYYMMDD') ) )
;
|