manju
manju

Reputation: 161

ORA-01861: literal does not match format string,

Currently I am trying to compare date fields with the below statement

AND (AIA.INVOICE_DATE >= NVL(TO_DATE(:P_INV_DT_FROM,'DD-MON-YYYY'), '01-JAN-1900')  
OR AIA.INVOICE_DATE IS NULL)
AND (AIA.INVOICE_DATE <= NVL(TO_DATE(:P_INV_DT_TO,'DD-MON-YYYY'), '31-DEC-4712')  
OR AIA.INVOICE_DATE IS NULL)

However, I am getting the below error,

ORA-01861: literal does not match format string 01861. 00000 - "literal does not match format string"

*Cause: Literals in the input must be the same length as literals in the format string (with the exception of leading whitespace). If the "FX" modifier has been toggled on, the literal must match exactly, with no extra whitespace.

*Action: Correct the format string to match the literal.

P.S: AIA.INVOICE_DATE is tn the form of 'DD-MON-YYYY' and p_inv_dt_from and p_inv_dt_to is in the form of 'YYYY/MM/DD HH24:MM:SS'

Upvotes: 0

Views: 2290

Answers (1)

KevinKirkpatrick
KevinKirkpatrick

Reputation: 1456

You need to explicitly identify the format of '01-JAN-1900' and '31-DEC-4712' (that is wrap them in TO_DATE('01-JAN-1900','DD-MON-YYYY')). Otherwise, Oracle will attempt to convert the strings to a date based on the environment session settings of whoever is running the code. Your session, for instance, may have NLS_DATE_FORMAT='MM/DD/YYYY', which isn't compatible with '01-JAN-1900'.

Upvotes: 2

Related Questions