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;
  • 相关阅读:
    Django各个文件中常见的模块导入
    js模板(template.js)实现页面动态渲染
    Netty 源码 Channel(一)概述
    Netty 源码 NioEventLoop(三)执行流程
    Netty 源码(一)Netty 组件简介
    Netty 源码(二)NioEventLoop 之 Channel 注册
    Java 算法(一)贪心算法
    Netty Reator(三)Reactor 模型
    Netty Reator(二)Scalable IO in Java
    Reactor 模型(一)基本并发编程模型
  • 原文地址:https://www.cnblogs.com/lovelyp/p/5069068.html
Copyright © 2011-2022 走看看