create table customers
(
customer_id integer constraint customers_pk primary key,
first_name varchar2(10) not null,
last_name varchar2(10) not null,
dob date,
phone varchar2(12)
);
这个建立的表
insert into customers (customer_id,first_name,last_name,dob,phone)
values(6,'Fred','Brown','01-JAN-1970','800-555-1215');我插入一条语句的时候提示错误,
ora--0483月份无效。
初学oralce请各位指教上面定义的constraint后面的customers_pk看的不是很明白,,学习oracle需要注意那些事情。
谢谢。
insert into customers (customer_id,first_name,last_name,dob,phone)
values(6,'Fred','Brown',to_date('1970-01-01','yyyy-mm-dd'),'800-555-1215');
这个是约束的名称报错的原因是你的时间格式不一致
select sysdate from dual
看看是什么格式 然后按照这个格式写时间就可以了或者使用to_date()
insert into customers (customer_id,first_name,last_name,dob,phone)
values(6,'Fred','Brown',to_date('01-01-1970','dd-mm-yyyy'),'800-555-1215');
--可以直接定义主键,在列后面加上primary key
create table customers(
customer_id integer primary key,
first_name varchar2(10) not null,
last_name varchar2(10) not null,
dob date,
phone varchar2(12)
);
也可与通过命令来修改:
alter table customers add constraint pk_constriant primary key(customer_id);更多修改表命令,参考:
oracle alter table详解
--修改成这样
insert into customers
(customer_id, first_name, last_name, dob, phone)
values
(6,
'Fred',
'Brown',
to_date('01-JAN-1970', 'DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN'),
'800-555-1215');