SQL每月自然周(中国习惯)

来源:互联网 发布:软件制作大师 编辑:程序博客网 时间:2024/05/21 17:42
select trunc(to_number(trunc(sysdate + 7 - (case
                               when to_char(sysdate, 'd') = '7' then
                                '6'
                               when to_char(sysdate, 'd') = '1' then
                                '7'
                               else
                                to_char(sysdate - 1, 'd')
                             end),
                             'd') - trunc(sysdate, 'mm')) / 7 + 1)
  from dual