and not (start_date >=to_date('2012-01-06 00:00:00','YYYY-MM-DD hh24:mi:ss') and start_date <=to_date('2012-01-06 08:59:59','YYYY-MM-DD hh24:mi:ss'))
and not (start_date >=to_date('2012-01-06 15:31:00','YYYY-MM-DD hh24:mi:ss') and start_date <=to_date('2012-01-06 23:59:59','YYYY-MM-DD hh24:mi:ss'))
and not (start_date >=to_date('2012-01-07 00:00:00','YYYY-MM-DD hh24:mi:ss') and start_date <=to_date('2012-01-07 08:59:59','YYYY-MM-DD hh24:mi:ss'))
and not (start_date >=to_date('2012-01-07 15:31:00','YYYY-MM-DD hh24:mi:ss') and start_date <=to_date('2012-01-07 23:59:59','YYYY-MM-DD hh24:mi:ss'))
and not (start_date >=to_date('2012-01-08 00:00:00','YYYY-MM-DD hh24:mi:ss') and start_date <=to_date('2012-01-08 08:59:59','YYYY-MM-DD hh24:mi:ss'))
and not (start_date >=to_date('2012-01-08 15:31:00','YYYY-MM-DD hh24:mi:ss') and start_date <=to_date('2012-01-08 23:59:59','YYYY-MM-DD hh24:mi:ss'))
;
--为了验证下面的SQL,添加一条 06-01-2012 15:31:00 的数据
insert into t_date_query (ID, NAME, START_DATE, CNT)
values (2, '002 ', to_date('06-01-2012 15:31:00', 'dd-mm-yyyy hh24:mi:ss'), 1);
delete from t_date_query
where start_date=to_date('06-01-2012 15:31:00', 'dd-mm-yyyy hh24:mi:ss');
--通过先控制YYYY-MM-DD 再控制 hh24:mi:ss的方法实现:(目前想到最好的实现方法)
select a.*
from t_date_query a
where start_date >= to_date('2012-01-06','YYYY-MM-DD') and start_date
and to_number(substr(to_char(start_date,'YYYY-MM-DD hh24:mi:ss'),12,2)||substr(to_char(start_date,'YYYY-MM-DD hh24:mi:ss'),15,2)) between 900 and 1530
order by start_date
;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11990065/viewspace-722096/
,如需转载,请注明出处,否则将追究法律责任。