I have the following DDL
and DML
statements :
create table emp_details (
ID number(2) constraint t_pk primary key,
F_Name varchar(10) not null,
L_Name varchar(10) not null,
DOB date,
Mob_no number(10),
City varchar(10),
PIN number(5),
Gender char(1),
Designation varchar(15),
Join_Date date,
);
insert into emp_details values (01,'John','Wick','1990-07-05',9856482358,'Goa',403001,'M','SDE II', '2015-01-08');
then, I get the error of ORA-01843
. So, what could be the problem?
The easiest thing to do here is to use ANSI date literals instead of strings for the dates (using strings will depend on the value of
NLS_DATE_FORMAT
and you don't want to play around with that if you don't have to):I have to add that explicitly listing the columns into which you're inserting values is a good habit to have. Otherwise, your
INSERT
query will break if you or someone else adds a column from your table:Last, another good practice is to use
VARCHAR2
instead ofVARCHAR
when you're working with Oracle. Currently they work the same, but Oracle "reserves the right" to changeVARCHAR
to meet with the ANSI standard under whichNULL
values and the empty string won't be the same (withVARCHAR2
they will always be the same). IOW, the behavior ofVARCHAR
values in Oracle can change.