Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Error: ORA-01861: literal does not match format string 01861

I am trying to insert data into an existing table and keep receiving an error.

INSERT INTO Patient   (   PatientNo,   PatientFirstName,   PatientLastName,   PatientStreetAddress,   PatientTown,   PatientCounty,   PatientPostcode,   DOB,   Gender,   PatientHomeTelephoneNumber,   PatientMobileTelephoneNumber ) VALUES  (   121,    'Miles',    'Malone',    '64 Zoo Lane',    'Clapham',    'United Kingdom',   'SW4 9LP',   '1989-12-09',   'M',   02086950291,   07498635200 ); 

Error:

Error starting at line : 1 in command - INSERT INTO Patient (PatientNo,PatientFirstName,PatientLastName,PatientStreetAddress,PatientTown,PatientCounty,PatientPostcode,DOB,Gender,PatientHomeTelephoneNumber,PatientMobileTelephoneNumber) VALUES (121, 'Miles', 'Malone', '64 Zoo Lane', 'Clapham', 'United Kingdom','SW4 9LP','1989-12-09','M',02086950291,07498635200) Error report - SQL 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. 

Just not sure why this keeps happening I am learning SQL at the moment, any help will be greatly appreciated!

like image 453
LizzyPooh Avatar asked Mar 20 '14 19:03

LizzyPooh


People also ask

How to solve ORA 01861 literal does not match format string?

You could correct the SQL statement as follows: SELECT TO_DATE('2004/08/13','yyyy/mm/dd') FROM dual; As a general rule, if you are using the TO_DATE function, TO_TIMESTAMP function, TO_CHAR function, and similar functions, make sure that the literal that you provide matches the format string that you've specified.

What does literal does not match format string mean in SQL?

This happens because you have tried to enter a literal with a format string, but the length of the format string was not the same length as the literal.

What is ORA 01861?

ORA-01861: 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.

How do I fix not valid Month error in Oracle?

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.


2 Answers

Try replacing the string literal for date '1989-12-09' with TO_DATE('1989-12-09','YYYY-MM-DD')

like image 137
mustaccio Avatar answered Oct 06 '22 02:10

mustaccio


The format you use for the date doesn't match to Oracle's default date format.

A default installation of Oracle Database sets the DEFAULT DATE FORMAT to dd-MMM-yyyy.

Either use the function TO_DATE(dateStr, formatStr) or simply use dd-MMM-yyyy date format model.

like image 44
2 revs, 2 users 62% Avatar answered Oct 06 '22 02:10

2 revs, 2 users 62%