このnot like
演算子は、値の数が 1 つの稼働日に 1 を超える場合の値の比較には適していません。以下の例では、最初の 2 行のレコードが一致し (太字 = 太字、斜体 = 斜体)、出力に表示されません。この問題は、'not like' 演算子のループが原因で発生します。
次のようにコードを簡略化しました。
SELECT e.EMP_NAME AS APS,
TO_CHAR (ws.WRKS_WORK_DATE, 'dd.mm.yyyy') AS Work_Date,
TO_CHAR ( (wd.WRKD_START_TIME), 'hh24:mi') AS Leave_Start_Time,
TO_CHAR ( (wd.WRKD_end_TIME), 'hh24:mi') AS Leave_End_Time,
TO_CHAR (sb.SHFTBRK_DEF_START, 'hh24:mi') AS shift_brk_Start,
TO_CHAR (sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES + 1) * .000694,
'hh24:mi')
AS shift_brk_end
FROM work.WORK_SUMMARY ws,
work.employee e,
work.work_detail wd,
work.TIME_CODE tc,
work.shift s,
work.shift_break sb,
work.EMPLOYEE_SCHEDULE es
WHERE ws.emp_id = e.emp_id
AND wd.WRKD_MINUTES < s.SHFT_VAL1 ---sum workd minutes less than shift id actual shift minutes
AND ws.WRKS_WORK_DATE BETWEEN '09-Jul-2013' AND '09-Jul-2013'
AND wd.WRKS_ID = ws.WRKS_ID
AND tc.TCODE_name IN
('COMP', 'SL COMP PEN', 'ARB','LUC',
'CMF', 'MREP', 'WSSL', 'RL',
'CBK', 'JUR', 'LSL', 'LSLT',
'LWPNC', 'LWPS', 'LWPTC', 'LWPU',
'LWOP', 'ML', 'MLHP', 'NWPTC',
'PAT', 'PL', 'SD', 'MSP',
'SUS', 'SUSW', 'WIT', 'CMPA',
'ABC', 'ABN', 'BER', 'COM',
'COMWP', 'IS', 'EXL', 'LFI',
'MER', 'NCD', 'PCLC', 'PCLS',
'PSLC', 'PSLN', 'PSLW', 'PSWO',
'PSLP', 'PURL', 'STU', 'UA',
'GRTW')
AND wd.TCODE_ID = tc.TCODE_ID
AND ws.PAYGRP_ID IN ('10023')
AND ws.WRKS_AUTHORIZED = 'Y'
AND e.EMP_TERMINATION_DATE >= CURRENT_DATE
--and e.emp_name in('1100376801','1100590701')
AND ws.WRKS_WORK_DATE = es.WORK_DATE
AND ws.emp_id = es.emp_id
AND ws.shft_id = es.EMPSKD_ACT_SHIFT_ID
AND es.EMPSKD_ACT_SHIFT_ID = s.SHFT_ID
AND s.SHFT_ID = sb.SHFT_ID
AND ( ( TO_CHAR (sb.SHFTBRK_DEF_START, 'hh24:mi') <=
TO_CHAR ( (wd.WRKD_START_TIME), 'hh24:mi')
AND TO_CHAR (
sb.SHFTBRK_DEF_START
+ (sb.SHFTBRK_MINUTES + 1) * .000694,
'hh24:mi') >
TO_CHAR ( (wd.WRKD_START_TIME), 'hh24:mi'))
OR ( TO_CHAR (sb.SHFTBRK_DEF_START, 'hh24:mi') <
TO_CHAR ( (wd.WRKD_end_TIME), 'hh24:mi')
AND TO_CHAR (
sb.SHFTBRK_DEF_START
+ (sb.SHFTBRK_MINUTES + 1) * .000694,
'hh24:mi') > TO_CHAR ( (wd.WRKD_end_TIME), 'hh24:mi'))
OR ( TO_CHAR (sb.SHFTBRK_DEF_START, 'hh24:mi') >
TO_CHAR ( (wd.WRKD_START_TIME), 'hh24:mi')
AND TO_CHAR (
sb.SHFTBRK_DEF_START
+ (sb.SHFTBRK_MINUTES + 1) * .000694,
'hh24:mi') < TO_CHAR ( (wd.WRKD_end_TIME), 'hh24:mi'))
OR ( TO_CHAR (sb.SHFTBRK_DEF_START, 'hh24:mi') =
TO_CHAR ( (wd.WRKD_end_TIME), 'hh24:mi')
AND TO_CHAR (
sb.SHFTBRK_DEF_START
+ (sb.SHFTBRK_MINUTES + 1) * .000694,
'hh24:mi') = TO_CHAR ( (wd.WRKD_end_TIME), 'hh24:mi')))
GROUP BY e.EMP_NAME,
ws.WRKS_WORK_DATE,
wd.WRKD_end_TIME,
wd.WRKD_START_TIME,
sb.SHFTBRK_DEF_START,
TO_CHAR (sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES + 1) * .000694,
'hh24:mi');
結果:
APS WORK_DATE LEAVE_START_TIME LEAVE_END_TIME SHIFT_BRK_START SHIFT_BRK_END
-------------------------------------------------------------------------------------
40151401 09.07.2013 10:00 13:00 10:30 11:00
40200001 09.07.2013 09:00 12:51 10:00 10:30
40447701 09.07.2013 09:30 14:15 10:00 10:30
40492101 09.07.2013 15:00 20:10 16:00 16:30
61037301 09.07.2013 10:35 14:15 11:00 11:30
64173401 09.07.2013 09:30 14:15 10:00 10:30
問題は、従業員 1100376801
のレコードが表示されることを期待していることです。レコードが表示されない理由は、欠落しているレコードの時刻が午前 0 時 ( 00:51) を超えているためです。 午前 0 時を超える時刻、つまり SHIFT_BRK_START と SHIFT_BRK_END の時刻が LEAVE_START_TIME と LEAVE_END_TIME の範囲内または範囲内に収まるように、「datetime」フィールドを別の形式にするにはどうすればよいですか。
期待される結果: 上記で返された結果に加えて、次のレコードも表示されるはずです。
APS WORK_DATE LEAVE_START_TIME LEAVE_END_TIME SHIFT_BRK_START SHIFT_BRK_END
-------------------------------------------------------------------------------------
11003701 09.07.2013 20:00 **0:51** 19:30 19:45
解像度:
and
(
(to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') < (wd.WRKD_START_TIME) and
to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES+1)*.000694, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') > (wd.WRKD_start_TIME))---1
OR(to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') =(wd.WRKD_START_TIME) and
to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES+1)*.000694, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') = (wd.WRKD_end_TIME))--4
OR(to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') =(wd.WRKD_START_TIME) and
to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES+1)*.000694, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') > (wd.WRKD_end_TIME))---5
OR(to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') =(wd.WRKD_START_TIME) and
to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES+1)*.000694, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') <(wd.WRKD_end_TIME))---5
OR (to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') > (wd.WRKD_START_TIME) and
to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES+1)*.000694, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') <= (wd.WRKD_end_TIME))---3
OR (to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') > (wd.WRKD_START_TIME) and
to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') < (wd.WRKD_end_TIME) and
to_date(to_char(wd.WRKD_START_TIME, 'dd.mm.yyyy') || '' || to_char(sb.SHFTBRK_DEF_START + (sb.SHFTBRK_MINUTES+1)*.000694, 'hh24:mi'), 'dd.mm.yyyy hh24:mi') > (wd.WRKD_end_TIME))---2
)