I have a problem when try to select data from a table filtering by date.
For example:
SELECT * FROM MYTABLE WHERE MYTABLE.DATEIN = '23/04/49';
The Oracle Error is:
Informe de error: Error SQL: ORA-01843: mes no válido 01843. 00000 - "not a valid month" *Cause: *Action:
Probably the source data of table is corrupted, in this case:
The results of this select, select * from nls_session_parameters;
, is:
PARAMETER VALUE ------------------------------ ---------------------------------------- NLS_LANGUAGE SPANISH NLS_TERRITORY SPAIN NLS_CURRENCY ¿ NLS_ISO_CURRENCY SPAIN NLS_NUMERIC_CHARACTERS ,. NLS_CALENDAR GREGORIAN NLS_DATE_FORMAT DD/MM/RR NLS_DATE_LANGUAGE SPANISH NLS_SORT SPANISH NLS_TIME_FORMAT HH24:MI:SSXFF NLS_TIMESTAMP_FORMAT DD/MM/RR HH24:MI:SSXFF NLS_TIME_TZ_FORMAT HH24:MI:SSXFF TZR NLS_TIMESTAMP_TZ_FORMAT DD/MM/RR HH24:MI:SSXFF TZR NLS_DUAL_CURRENCY ¿ NLS_COMP BINARY NLS_LENGTH_SEMANTICS BYTE NLS_NCHAR_CONV_EXCP FALSE
To fix the error, specify a month value that is valid such as “January”. Some conversion is built-in, and a value of “Jan” is also valid for the Month format code.
Fix: To fix this, update your SQL statement to remove the mistake and use the correct month value. SELECT TO_DATE('01-JAN-2015') FROM dual; If the value is correct, and you're still getting the error, it could be to do with the format you've entered. TO_DATE allows you to enter a format along with the input value.
RR is an "input" format. it means if you enter to_date( '01-jan-40', 'dd-mon-rr' ) Oracle will slide around the date based on the current year. In 1999 and 2001 -- that would be the year 2040. As opposed to yy -- where the century is based on the current date.
Oracle stores dates in an internal numeric format representing the century, year, month, day, hours, minutes, seconds. The default date format is DD-MON-YY. SYSDATE is a function returning date and time. DUAL is a dummy table used to view SYSDATE.
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');
You are comparing a date column to a string literal. In such a case, Oracle attempts to convert your literal to a date, using the default date format. It's a bad practice to rely on such a behavior, as this default may change if the DBA changes some configuration, Oracle breaks something in a future revision, etc.
Instead, you should always explicitly convert your literal to a date and state the format you're using:
SELECT * FROM MYTABLE WHERE MYTABLE.DATEIN = TO_DATE('23/04/49','MM/DD/YY');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With