ORA-01861: literal does not match format string

后端 未结 4 1369
南方客
南方客 2020-12-06 03:58

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:         


        
相关标签:
4条回答
  • 2020-12-06 04:20

    The error means that you tried to enter a literal with a format string, but the length of the format string was not the same length as the literal.

    One of these formats is incorrect:

    TO_CHAR(t.alarm_datetime, 'YYYY-MM-DD HH24:MI:SS')
    TO_DATE(alarm_datetime, 'DD.MM.YYYY HH24:MI:SS')
    
    0 讨论(0)
  • 2020-12-06 04:22

    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.

    0 讨论(0)
  • 2020-12-06 04:22

    Just before executing the query: alter session set NLS_DATE_FORMAT = "DD.MM.YYYY HH24:MI:SS"; or whichever format you are giving the information to the date function. This should fix the ORA error

    0 讨论(0)
  • 2020-12-06 04:30
    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_char (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 
    
    0 讨论(0)
提交回复
热议问题