使用序列和触发器创建标识列。但由于最后缺少半冒号而无法运行脚本
create table slide1 ( id number(10),
subject varchar2(25),constraint pk_id PRIMARY KEY(id)
);
Create sequence slide1_sequence start with 1
increment by 1
minvalue 1
maxvalue 10000;
create sequence id_seq;
CREATE OR REPLACE TRIGGER slide1_trigger
BEFORE INSERT ON slide1
FOR EACH ROw
BEGIN
SELECT slide1_seq.NEXTVAL
INTO :new.id
FROM dual
close slide1;
END;
答案 0 :(得分:1)
SQL> create table slide1 ( id number(10),subject varchar2(25),constraint pk_id PRIMARY KEY(id));
Table created
SQL> Create sequence slide1_sequence start with 1 increment by 1 minvalue 1 maxvalue 10000;
Sequence created
SQL> create sequence id_seq;
Sequence created
SQL> CREATE OR REPLACE TRIGGER slide1_trigger
2 BEFORE INSERT ON slide1
3 FOR EACH ROw
4
5 BEGIN
6 SELECT slide1_sequence.NEXTVAL
7 INTO :new.id
8 FROM dual;
9 END;
10
11 /
Trigger created