SELECT * FROM COACH_SHOP_OPERATION_F
WHERE TRUNC(coach_last_event_dt)=TO_DATE(TO_CHAR('MAY 25,2015','DD-MON-YYYY'),'DD-MON-YYYY')
运行此查询会导致错误:
01722-无效数
答案 0 :(得分:0)
这似乎有效:
SELECT * FROM COACH_SHOP_OPERATION_F
WHERE TRUNC(coach_last_event_dt)=TO_DATE('MAY 25,2015','MON DD,YY')
SQLFIDDLE(感谢Alex Poole)
答案 1 :(得分:0)
您的日期与语言相关,因此您应添加其他参数(例如德语):
TO_DATE('MAI 25,2015','MONTH DD,YYYY', 'NLS_DATE_LANGUAGE = GERMAN')
或英语语言
TO_DATE('MAY 25,2015','MONTH DD,YYYY', 'NLS_DATE_LANGUAGE = ENGLISH')
答案 2 :(得分:0)
TO_CHAR('MAY 25,2015','DD-MON-YYYY')
'MAY 25,2015'
是字符串,您在字符串上使用 TO_CHAR ,没有任何意义。您需要 TO_DATE 将字符串转换为DATE,并使用TO_CHAR将DATE转换为字符串以便以您想要的格式显示。
'MAY 25,2015','DD-MON-YYYY'
MON DD,YYYY
TO_DATE(TO_CHAR('MAY 25,2015','DD-MON-YYYY'),'DD-MON-YYYY')
TO_DATE('MAY 25,2015','MON DD,YYYY', 'NLS_DATE_LANGUAGE = ENGLISH')
TRUNC(coach_last_event_dt)
between to_date('25/05/2015','DD/MM/YYYY')
and to_date('25/05/2015','DD/MM/YYYY') + 1;
您修改过的查询如下所示:
SELECT *
FROM COACH_SHOP_OPERATION_F
WHERE coach_last_event_dt
BETWEEN
TO_DATE('MAY 25,2015','MON DD,YYYY', 'NLS_DATE_LANGUAGE = ENGLISH')
AND
TO_DATE('MAY 25,2015','MON DD,YYYY', 'NLS_DATE_LANGUAGE = ENGLISH') + 1;