Oracle计算自然周
转 http://blog.csdn.net/wh62592855/article/details/4739492
create or replace function Getweekbydate(sdate in date) return number is Result number; begin select to_char(decode(sign((to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd') + to_number(decode(to_char(trunc(to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd'), 'yyyy'), 'd'), '1', '8', to_char(trunc(to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd'), 'yyyy'), 'd'))) - 2) - last_day(to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd'))), 1, last_day(to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd')), (to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd') + to_number(decode(to_char(trunc(to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd'), 'yyyy'), 'd'), '1', '8', to_char(trunc(to_date(to_char(sdate, 'yyyymmdd'), 'yyyymmdd'), 'yyyy'), 'd'))) - 2)), 'ww') into result from dual; return Result; end Getweekbydate;
天行健,君子以自强不息