篩選出0點到早上8點之間進入的所有記錄 查詢結果如下: ...
-- Crea1te table create table TESTDB ( ID NVARCHAR2(20), INTIME DATE,/*進入時間*/ OUTTIME DATE/*出去時間*/ ) tablespace LBSBUS pctfree 10 pctused 40 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );
插入測試數據
insert into TESTDB (ID, INTIME, OUTTIME) values ('1', to_date('13-05-2017 10:58:58', 'dd-mm-yyyy hh24:mi:ss'), to_date('13-05-2017 15:58:58', 'dd-mm-yyyy hh24:mi:ss')); insert into TESTDB (ID, INTIME, OUTTIME) values ('2', to_date('16-05-2017 20:58:59', 'dd-mm-yyyy hh24:mi:ss'), to_date('16-05-2017 23:58:59', 'dd-mm-yyyy hh24:mi:ss')); insert into TESTDB (ID, INTIME, OUTTIME) values ('3', to_date('18-05-2017 21:58:59', 'dd-mm-yyyy hh24:mi:ss'), to_date('18-05-2017 22:58:59', 'dd-mm-yyyy hh24:mi:ss')); insert into TESTDB (ID, INTIME, OUTTIME) values ('4', to_date('19-06-2017 02:58:59', 'dd-mm-yyyy hh24:mi:ss'), to_date('19-06-2017 07:58:59', 'dd-mm-yyyy hh24:mi:ss')); insert into TESTDB (ID, INTIME, OUTTIME) values ('5', to_date('20-06-2017 03:59:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('20-06-2017 08:59:00', 'dd-mm-yyyy hh24:mi:ss'));
篩選出0點到早上8點之間進入的所有記錄
select * from TESTDB where to_char(INTIME,'hh24:mi:ss') between '00:00:00' and '08:00:00'
查詢結果如下:
打完收工!