oracle序列 自动增加

来源:互联网 发布:37琅琊榜光翼进阶数据 编辑:程序博客网 时间:2024/05/14 05:30
 

普通用户普通身份
create user yao identified by "654321"
grant connect,resource to yao
conn yao/654321


create table TP
(
    ProID NUMBER primary key,
    ProName VARCHAR2(20)
);
创建序列
create sequence SE
minvalue 1
maxvalue 9999999
start with 1
increment by 1
NOCYCLE
NOCACHE;

创建触发器
  create or replace trigger tp_se
  before insert on TP
  for each row
  begin
     select se.nextval into:new.ProID from dual;
  end;

插入数据
insert into TP values (1,'aa')
insert into TP (ProName) values ('bb')

原创粉丝点击