Oracle,지난주 월요일 부터 주말 까지 의 조회 sql 문 구 를 가 져 옵 니 다.

 
-- Oracle sql

-- ,
select to_char(to_date('20130906','yyyymmdd'),'d') from dual;
-- :6 :2013.09.06 ,

select to_char(sysdate+(2-to_char(sysdate,'d'))-7,'yyyymmdd') from dual;---
select to_char(sysdate+(2-to_char(sysdate,'d'))-1,'yyyymmdd') from dual;---

-- , date
select trunc(sysdate,'iw') - 7 from dual;---
select trunc(sysdate,'iw') - 1 from dual;--

--
select trunc(sysdate,'iw') from dual;

select trunc(to_date('20130915','yyyymmdd'),'iw') from dual;
-- :2013/9/9 :20130915

-- char
select to_char(trunc(sysdate,'iw') - 7,'yyyymmdd') from dual;--
select to_char(trunc(sysdate,'iw') - 1,'yyyymmdd') from dual;--

--
create or replace function fun_acc_getlastweekstart(systemdate in date)
return varchar2 is
result_str varchar2(15);
begin
select to_char(trunc(systemdate, 'iw') - 7, 'yyyymmdd')
into result_str
from dual;
return result_str;
end fun_acc_getlastweekstart;

--
create or replace function fun_acc_getlastweekend(systemdate in date) return varchar2 is
result_str varchar2(15);
begin
select to_char(trunc(systemdate, 'iw') - 1, 'yyyymmdd')
into result_str
from dual;
return result_str;
end fun_acc_getlastweekend;

--
select fun_acc_getlastweekstart(sysdate) from dual;
select fun_acc_getlastweekend(sysdate) from dual;
select fun_acc_getlastweekstart(to_date('20130915','yyyymmdd')) from dual;
select fun_acc_getlastweekend(to_date('20130915','yyyymmdd')) from dual;
-- :20130826、20130901、20130902、20130908
-- :
select sysdate from dual;
-- :2013/9/6 9:45:14

좋은 웹페이지 즐겨찾기