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')

  • 相关阅读:
    实现Callable接口实现多线程
    匿名内部类方式实现
    实现Runnable接口方式
    后台线程
    继承Thread类
    线程中断详解
    第六章、Linux 的档案权限不目彔配置
    安装virtual box
    CISCO实验记录六:EIGRP路由协议
    zabbix监控项整理Items-key
  • 原文地址:https://www.cnblogs.com/hq233/p/12199676.html
Copyright © 2011-2022 走看看