Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I try to execute this snippet:

cmd.CommandText = "SELECT alarm_id,definition_description,element_id,
    TO_CHAR (alarm_datetime, 'YYYY-MM-DD HH24:MI:SS'),severity,
    problem_text,status FROM aircom.alarms 
    WHERE status = 1 and 
    TO_DATE (alarm_datetime,'DD.MM.YYYY HH24:MI:SS') > TO_DATE ('07.09.2008 
    09:43:00', 'DD.MM.YYYY HH24:MI:SS') 
    order 
    by ALARM_DATETIME desc";

I get:

ORA-01861: literal does not match format string

There is no problem with database connection because I can execute basic SQL commands.

What is the problem with this statement?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
525 views
Welcome To Ask or Share your Answers For Others

1 Answer

Remove the TO_DATE in the WHERE clause

TO_DATE (alarm_datetime,'DD.MM.YYYY HH24:MI:SS')

and change the code to

alarm_datetime

The error comes from to_date conversion of a date column.

Added Explanation: Oracle converts your alarm_datetime into a string using its nls depended date format. After this it calls to_date with your provided date mask. This throws the exception.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...