我正在尝试选择时间范围内所有可用的记录。
我需要从 TABLE2 中获取一个时间戳,并获取 TABLE1 中在该时间到当前时间之间的所有记录。
SELECT COUNT(*)
FROM TABLE1
WHERE STATUS = 'COMPLETED'
AND LAST_UPDATE_USER = 'myID'
AND LAST_UPDATE_DT BETWEEN
TO_DATE((
SELECT /*+PARALLEL(16)*/ SIGN_IN_DT
FROM TABLE2
WHERE ID = 'myID'
AND SIGNED_SCREEN = 'screen1'
AND SIGN_OFF_DT IS NULL),
'dd-mon-yyyy hh24:mi:ss.ff')
AND SYSDATE;
两个表中的 日期格式 = 05-MAR-19 07.47.26.769934000 PM
我得到了例外:
ORA-01821:日期格式无法识别
请帮助。
答案 0 :(得分:1)
尝试以下查询:
select * from table1 t1
join table2 t2 on t1.last_update_user = t2.ID
where t1.status = 'COMPLETED'
and t1.last_update_user = 'myID'
and t2.signed_screen = 'screen1'
and t2.sign_off_dt is null
and t1.last_update_dt between t2.sign_in_dt and sysdate;