Home > database >  Oracle SQL having troubles inserting values into a table
Oracle SQL having troubles inserting values into a table

Time:11-10

Trying to insert some values into a table and always showing me some errors, i think it has something to do with the date or smth but not quite sure about that, if anyone knows what's wrong, please let me know...

The error that currently shows me is:

ORA-01861: literal does not match format string ORA-06512: at "SYS.DBMS_SQL", line 1721

INSERT INTO Cats VALUES ('JACEK','M','CAKE','CATCHING','BALD','2008-12-01',67,NULL,2);

Here's the table:

CREATE TABLE Cats (
    name VARCHAR2(15) CONSTRAINT cat_name_nn NOT NULL,
    gender VARCHAR2(1) CONSTRAINT cat_gen_ch CHECK (gender IN('M', 'W')),
    nickname VARCHAR2(15) CONSTRAINT cat_pk PRIMARY KEY,
    function VARCHAR2(10), 
    chief VARCHAR2(15), 
    in_herd_since DATE DEFAULT SYSDATE CONSTRAINT cat_inherd_nn NOT NULL,
    mice_ration NUMBER(3),
    mice_extra NUMBER(3),
    band_no NUMBER(2),
    CONSTRAINT cat_banno_fk FOREIGN KEY (band_no) REFERENCES Bands(band_no),
    CONSTRAINT cat_chief_fk FOREIGN KEY (chief) REFERENCES Cats(nickname),
    CONSTRAINT cat_fun_fk FOREIGN KEY (function) REFERENCES Functions(function)
);

CodePudding user response:

when entering character values for a column whose data type is Date you have to convert it into a DATE by using the TO_DATE function. In you case the column in_herd_since is of DATE type , you should try this

TO_DATE('2008-12-01', 'YYYY-MM-DD') -- untested

INSERT INTO Cats VALUES ('JACEK','M','CAKE','CATCHING','BALD',
TO_DATE('2008-12-01', 'YYYY-MM-DD'),67,NULL,2);
  • Related