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;
  • 相关阅读:
    python入门(变量命名规则)
    基础数据类型(不可变数据类型)
    记录Linux下安装elasticSearch时遇到的一些错误
    利用谷歌 kaptcha 进行验证码生成
    分布式拒绝服务攻击
    python3.5文档
    python反射机制
    tornado 使用tornado让你的请求异步非阻塞
    tornado的入门教程
    spark 环境变量系列配置
  • 原文地址:https://www.cnblogs.com/lovelyp/p/5069068.html
Copyright © 2011-2022 走看看