Skip to content
Advertisement

Insert query returns error : SQL Error: ORA-01861: literal does not match format string

I have this simple enough insert query but i have no idea why it is returning an error. i can see the error comes from the row Birthay, if i remove it the insert is done ok. My query:

INSERT
INTO DATA_INDIVID
 (
ACCOUNT_NUMBER,
ACCOUNT_NUMBER_TYPE,
ACCOUNT_STATUS,
FIRST_NAME,
MIDDLE_NAME,
LAST_NAME,
COUNTRY_OF_RESIDENCE,
TAX_IDENTIFICATION_NUMBER,
ADDRESS,
To_Date (BIRTHDAY) BIRTH
 )
 VALUES
(
'44444',
'11111',
'Close',
'LEC',
'xxxx',
'yyyyy',
'GR',
'11111111111',
'test/test/test 1234',
'1978-06-24'
 );

it is returning this error

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

Thank you in advance

Advertisement

Answer

Just use the column name in the list of columns and a DATE literal in the VALUES clause:

INSERT INTO DATA_INDIVID
(
  ACCOUNT_NUMBER,
  ACCOUNT_NUMBER_TYPE,
  ACCOUNT_STATUS,
  FIRST_NAME,
  MIDDLE_NAME,
  LAST_NAME,
  COUNTRY_OF_RESIDENCE,
  TAX_IDENTIFICATION_NUMBER,
  ADDRESS,
  BIRTHDAY
) VALUES (
  '44444',
  '11111',
  'Close',
  'LEC',
  'xxxx',
  'yyyyy',
  'GR',
  '11111111111',
  'test/test/test 1234',
  DATE '1978-06-24'
);

You could also use:

TO_DATE( '1978-06-24', 'YYYY-MM-DD' )

in the values clause.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement