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!
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.
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.
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.
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.
Try replacing the string literal for date '1989-12-09'
with TO_DATE('1989-12-09','YYYY-MM-DD')
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.
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