Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle - literal does not match format string error [duplicate]

Possible Duplicate:
Simple Oracle query: literal does not match format string

I am getting the following error:

INSERT INTO CatalogueEntry VALUES('2001-12-10', 2, 14.99, 1, 0)

ERROR at line 1: ORA-01861: literal does not match format string `

The first field is a DATE format.

Any ideas?

Thanks.

like image 969
AkshaiShah Avatar asked Nov 22 '12 18:11

AkshaiShah


People also ask

What is the error literal does not match format string?

This error occurs when a literal is entered with a format string, but the length of such format string is not the same as the literal. This can sometimes occur in Tableau Desktop when using the DATE() function along with an Oracle database.

How do I fix this Ora-01861 literal does not match format string?

You should fix it as follows. SELECT TO_DATE('05/05/2021','dd/mm/yyyy') FROM dual; You need to provide the correct literal when you use TO_DATE function, TO_TIMESTAMP function, TO_CHAR function, and similar functions.

What is the error ORA-01861?

The ORA-01861 lists as resulting when “literal does not match format string”. If you're not privy to these terms then this can seem a bit unclear. However, once you're familiar with the two terms the rest falls right into place. A literal in Oracle is a fixed, specific data point.

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.


1 Answers

When you are inserting a string value to a date column, then you need to convert it to a date during the INSERT using the to_date() function. When using this function you will provide the format of the string.

to_date() function format:

to_date( string1, [ format_mask ], [ nls_language ] )

So your query will be like this:

insert into CatalogueEntry
values
(
  to_date('2001-12-10', 'yyyy-mm-dd'),
  2,
  14.99,
  1,
  0);

See SQL Fiddle with demo

like image 176
Taryn Avatar answered Oct 11 '22 13:10

Taryn