M
M
mosikus2022-04-11 14:38:27
Oracle
mosikus, 2022-04-11 14:38:27

Why does it throw a literal does not match format string error when adding a date?

Hello. I look here https://livesql.oracle.com/
I create a table

CREATE TABLE people(
last_name varchar2(64) NOT NULL,
first_name varchar2(64),
sex char NOT NULL CHECK(sex = 'f' OR sex = 'm'),
birthday date,
PRIMARY KEY(last_name, first_name, birthday)
);

then I try to add a line
INSERT INTO people (last_name, first_name, sex, birthday)
VALUES ('Иванов', 'Иван', 'm', '1999-04-04');

and i get an error
ORA-01861: literal does not match format string ORA-06512: at "SYS.DBMS_SQL", line 1721

How to write the date correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2022-04-11
@mosikus

Try TO_DATE :

INSERT INTO people (last_name, first_name, sex, birthday)
VALUES ('Иванов', 'Иван', 'm', to_date('1999-04-04', 'yyyy-mm-dd'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question