分几个维度校验吧。。
四个维度
存在start is null and end id null任何数据都不能插入
取出所有start is null and end最大的值,插入的值不能比最大的end小。。
取出所有end is null and start 最小的值,插入的值不能比最小的start 大。
最后插入的值不能在所有start与end的之间。。可以用子查询判断。。
综上,只有都满足才可以插入,否则不允许插入。

解决方案 »

  1.   

    写个存储过程吧,一个sql语句实现不了吧
      

  2.   

    这个只是where条件比较复杂点,但是他们应该有交集,考虑完全了应该不是很复杂,一个sql可以搞定, 谁能比较间的写出来啊?
      

  3.   

    你要的是insert,不是select ,哪来的where条件?
      

  4.   

    select count(*) from t where greatest(插入的start,nvl(start,date '0001-01-01')) < least(插入的end,nvl(end,date '9999-12-31'))大于0则不能 等于0则能
      

  5.   


    其实如果你可以保证不需要插空的话,直接:start_time>decode(end_time,
                          null,
                          to_date('4000-12-31', 'yyyy-mm-dd'),
                          end_time)即可,但是如果需要插空就得比较麻烦了:
    select *
      from (select decode(start_time,
                          null,
                          to_date('1000-12-31', 'yyyy-mm-dd'),
                          start_time) start_time,
                   decode(end_time,
                          null,
                          to_date('4000-12-31', 'yyyy-mm-dd'),
                          end_time) end_time
              from tab) a,
           (select decode(start_time,
                          null,
                          to_date('1100-12-31', 'yyyy-mm-dd'),
                          start_time) new_start_time,
                   decode(end_time,
                          null,
                          to_date('3000-12-31', 'yyyy-mm-dd'),
                          end_time) new_end_time
              from new_tab) b
     where a.start_time between b.new_start_time and b.new_end_time
        or a.end_time between b.new_start_time and b.new_end_time
        or (a.start_time < b.new_start_time and a.end_time > b.new_end_time)这里应该不存在start null  end not null 的情况吧
      

  6.   

    我说的插空是中间有段时间可以使用的意思。不是insert null的意思