zoukankan      html  css  js  c++  java
  • Oracle:Decode在时间范围中的使用

    做查询的时候需要下一个sql,需要select test_time出来,如果test_Time的HH24:Mi:SS在7:00:00和19:00:00返回白班,否则返回夜班

      select case when to_number(to_char(test_time, 'hh24')) between 7 and 19 then '白班'

      else '夜班'

      end

      from (select to_date('2008-12-5 10:00:00', 'yyyy-mm-dd hh24:mi:ss') test_time

      from dual

      ) t;

      SQL> SELECT MYDATE,

      2         DECODE(SIGN(MYDATE-TO_DATE(TO_CHAR(MYDATE,'YYYY-MM-DD')||'07:00:00','YYYY-MM-DD HH24:MI:SS'))

      3               *SIGN(TO_DATE(TO_CHAR(MYDATE,'YYYY-MM-DD')||'19:00:00','YYYY-MM-DD HH24:MI:SS')-MYDATE),

      4               1,'Morning Shift',

      5               0,'Morning Shift',

      6               'Afternoon Shift') CLASS_TYPE

      7    FROM TABLE_NAME TT;

      MYDATE                                             CLASS_TYPE

      -------------------------------------------------- ---------------

      2008-12-3 6:30:55                                  Afternoon Shift

      2008-12-3 10:42:33                                 Morning Shift

      2008-12-3 19:22:36                                 Afternoon Shift

      2008-12-3 19:00:00                                 Morning Shift

      2008-12-4 7:00:00                                  Morning Shift

  • 相关阅读:
    【翻译】How To Tango With Django 1.5.4 第五章
    【翻译】How To Tango With Django 1.5.4 第四章
    阅读廖雪峰老师git教程笔记
    【翻译】How To Tango With Django 1.5.4 第二章
    Spring MVC @PathVariable 特殊字符
    http 缓存相关
    response contentType
    c++ 中 define
    转:java native
    浅析Java中的final关键字
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/3727140.html
Copyright © 2011-2022 走看看