我的表中有两个时间字段:t1与t2。 格式类似:2007-4-2 10:01:01
想得到字段 t = (t2-t1)*24 (小时)。
但若t1到t2在22:00到第二天8:00之间,这一段时间不能计算在内。如 t1='2007-4-2 1:0:0'   t2 = '2007-4-2 9:0:0'
由于 '2007-4-2 1:0:0' 到'2007-4-2 8:0:0'不算,t=1小时。
请问各位大侠如何实现。

解决方案 »

  1.   

    select (decode(sign(t1 - (trunc(t1) + 22 / 24)),
                   1,
                   0,
                   (trunc(t1) + 22 / 24) - t1) +
           decode(sign(t2 - (trunc(t2) + 8 / 24)),
                   1,
                   t2 - (trunc(t2) + 8 / 24),
                   0)) * 24
      from tab_name