我想在SQL中执行以下操作:
我有三个班次:
班次1:07:00-14:59左移2:15:00-22:59左移3:23:00 - 6点59分
我想知道我实际上在哪个班次,这取决于我的sysdate(时间)。 以下声明不适用于“02:00”。 start_time和end_time是varchar2
SELECT * FROM abc
WHERE to_char(sysdate, 'HH24:MI')
between start_time and end_time;
我该怎么做?
答案 0 :(得分:2)
select *
from abc
where mod(EXTRACT(HOUR FROM CAST(sysdate AS TIMESTAMP))+1,24)
between mod(EXTRACT(HOUR FROM CAST(to_date(start_time,'hh24:mi') AS TIMESTAMP))+1,24)
and mod(EXTRACT(HOUR FROM CAST(to_date(end_time,'hh24:mi') AS TIMESTAMP))+1,24)