Error ORA-01861: Resolving DateTime Format Mismatch
Encountering error ORA-01861 when inserting data into a table is indicative of a mismatch between the format of the input literal and the expected format specified in the SQL statement. To resolve this error, it's crucial to ensure that both formats align.
Specifically, in the given example, the issue lies with the DOB (date of birth) field in the INSERT statement:
DOB, '1989-12-09',
The literal string '1989-12-09' does not match the implicit format expected by the Oracle database for date values. To rectify this, you can use the TO_DATE() function to explicitly convert the string into a date value with the correct format:
DOB, TO_DATE('1989-12-09', 'YYYY-MM-DD')
In this case, the TO_DATE function takes the first argument as the string representation of the date, and the second argument specifies the format of that string. The 'YYYY-MM-DD' format ensures that the date is interpreted as a year-month-day value.
Oracle requires that the literal data provided for insertion matches the format expected by the target column. By converting the DOB string literal to the correct format using TO_DATE(), you can eliminate the ORA-01861 error and successfully insert the data into the table.
The above is the detailed content of How to Resolve the ORA-01861: Literal does not match format string Error in Oracle?. For more information, please follow other related articles on the PHP Chinese website!