zoukankan      html  css  js  c++  java
  • oracle根据月份获取每周的始末日期

    with t1 as

     (select level id, '201507' || lpad(level, 2, '0') col
        from dual
      connect by level < 32),
    t2 as
     (select 0 id,
             null,
             to_char(trunc(to_date(col, 'yyyymmdd'), 'month'), 'yyyymmdd') end_dt
        from t1
       where rownum = 1
      union all
      select 32,
             null,
             '-' || to_char(last_day(trunc(to_date(col, 'yyyymmdd'), 'month')),
                            'yyyymmdd')
        from t1
       where rownum = 1
      union all
      select id,
             to_date(col, 'yyyymmdd'),
             decode(to_number(to_char(to_date(col, 'yyyymmdd'), 'D')) - 1,
                    0,
                    '-' || col,
                    1,
                    col)
        from t1
       where col <= to_char(last_day(trunc(to_date(substr(col, 1, 6) || '01',
                                                   'yyyymmdd'),
                                           'month')),
                            'yyyymmdd')),
    t3 as
     (select id,
             decode(instr(lag(end_dt, 1) over(order by id), '-'),
                    1,
                    null,
                    lag(end_dt, 1) over(order by id)) start_dt,
             end_dt
        from t2
       where end_dt is not null
       order by id)
    select '第' || rownum || '周:' des, start_dt || end_dt
      from t3
     where start_dt is not null
     order by id;
  • 相关阅读:
    【Java线程】Java线程池ExecutorService
    MappedByteBuffer高速缓存文件、RandomAccessFile随机访问
    RandomAccessFile和memory-mapped files
    花1K内存实现高效I/O的RandomAccessFile类
    家庭局域网的组建(2台或2台以上)
    设置IE浏览器代理上网
    局域网Internet的共享
    三层设备---路由器
    二层设备---网桥和交换机
    底层设备---中继器和集线器
  • 原文地址:https://www.cnblogs.com/lovelyp/p/5069068.html
Copyright © 2011-2022 走看看