1、在scott用户下建立表dept(其实oracle缺省安装就已经生成了)
create table DEPT
(
DEPTNO NUMBER(2) not null,
DNAME VARCHAR2(14),
LOC VARCHAR2(13)
)
2、建立一个sequence
create sequence seq_dept
minvalue 1
start with 1
increment by 1
nocache;
3、为dept表建立一个insert trigger
create or replace trigger insert_dept
before insert on dept
for each row
declare
-- local variables here
begin
select seq_dept.nextval into :new.deptno from dual;
end insert_dept;
4、用insert语句测试
insert into dept(dname,loc) values( 'aaaaaa ', 'bbbbb ');
用select * from dept察看结果
阅读(1058) | 评论(0) | 转发(0) |