zoukankan      html  css  js  c++  java
  • Oracle的overlaps函数转换其他数据库语法

    首先,来介绍一下Oracle的overlaps函数的用法:

    overlaps函数是用来判断两个时间段是否有重叠的

    比如说计算 (a,b),(c,d)

    就可以写成:

    select * from dual where (a,b) overlaps (c,d);

    其中abcd都是日期格式。

    注意:比较的只能是日期。如果是数字,则会报错 ORA-00932: inconsistent datatypes

    最近项目在使用db2数据库,遇到overlaps函数需要转换成db2中的语法方言,其实就是转换为通用的sql语法。

    对应的写法有:

    判断两个时间段是否有重叠

    (a,b),(c,d)

    判断两段时间是否有重叠

    方法一

    select 'yes' from dual where d>a and c<b;

    例子:

    select *
    from PMK_PLANNING_INFO
    where id = 'U2KsqII5NdumrClO5td'
    and to_date('2019/07/27', 'YYYY/MM/DD') > to_date(begin_time)
    and to_date('2018/06/27', 'YYYY/MM/DD') < to_date(end_time);

    方法二

    select 'yes' from dual where (a, b) overlaps (c,d);

    例子:

    select *
    from PLANNING_INFO
    where id = '001'
    and (to_date(begin_time), to_date(end_time))
    overlaps
    (to_date('2018/06/27', 'YYYY/MM/DD'),
    to_date('2019/07/27', 'YYYY/MM/DD'));

    方法三

    select 'yes' from dual where a between c and d or d between a and b;

    例子:

    select *
    from PMK_PLANNING_INFO
    where id = 'U2KsqII5NdumrClO5td'
    and to_date(begin_time) between to_date('2018/06/27', 'YYYY/MM/DD') and to_date('2019/07/27', 'YYYY/MM/DD')
    or to_date('2019/07/27', 'YYYY/MM/DD') between to_date(begin_time) and to_date(end_time);

    a : to_date(begin_time)

    b :to_date(end_time)

    c :to_date('2018/06/27', 'YYYY/MM/DD')

    d :to_date('2019/07/27', 'YYYY/MM/DD')

  • 相关阅读:
    Oracle Hint的用法
    利用flashback transaction query新特性进行事务撤销
    存储的一些基本概念(HBA,LUN)
    SAN和NAS
    SAN (Storage Attached Network),即存储区域网络
    深入浅出谈存储之NAS是什么
    对于NAS,IP SAN以及iSCSCI SAN存储的一些认识和理解
    Oracle的体系结构
    利用360免费wifi搭建局域网让他人访问Oracle数据库
    杭电ACM id:3783
  • 原文地址:https://www.cnblogs.com/hq233/p/12199676.html
Copyright © 2011-2022 走看看