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

  • 相关阅读:
    Rust-数据类型
    Rust-智能指针
    Rust-使用包、Crate和模块管理不断增长的项目
    Rust-Slice类型
    Rust-引用与借用
    Rust 的核心功能-所有权(ownership)
    How to fix “sudo: command not found error”
    ABC195 F
    CF1501D Two chandeliers【拓展欧几里得+二分】
    CCA的小球【容斥定理】
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/3727140.html
Copyright © 2011-2022 走看看