ORA-01843 not a valid month- Comparing Dates

前端 未结 9 2220
南方客
南方客 2020-12-15 03:49

I have a problem when try to select data from a table filtering by date.

For example:

SELECT * FROM MYTABLE WHERE MYTABLE.DATEIN = \'23         


        
相关标签:
9条回答
  • 2020-12-15 04:45

    In a comment to one of the answers you mention that to_date with a format doesn't help. In another comment you explain that the table is accessed via DBLINK.

    So obviously the other system contains an invalid date that Oracle cannot accept. Fix this in the other dbms (or whatever you dblink to) and your query will work.

    Having said this, I agree with the others: always use to_date with a format to convert a string literal to a date. Also never use only two digits for a year. For example '23/04/49' means 2049 in your system (format RR), but it confuses the reader (as you see from the answers suggesting a format with YY).

    0 讨论(0)
  • 2020-12-15 04:49

    If the source date contains minutes and seconds part, your date comparison will fail. you need to convert source date to the required format using to_char and the target date also.

    0 讨论(0)
  • 2020-12-15 04:52

    You should use the to_date function (oracle/functions/to_date.php )

    SELECT * FROM MYTABLE WHERE MYTABLE.DATEIN = TO_DATE('23/04/49', 'DD/MM/YY');
    
    0 讨论(0)
提交回复
热议问题