-- 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