Oracle实现自增长列
第一步:新建一张测试表如下
create table KING
(
ID NUMBER(10),
NAME NVARCHAR2(2000)
)
第二步:新建序列
create sequence KING_TB_SEQ
minvalue 1
maxvalue 9999999999
start with 21
increment by 1
cache 20;
第三步:创建相应的触发器
create or replace trigger king_tb_tri
before insert on King
for each row
begin
select king_tb_seq.nextval into :new.Id from dual;
end;
第四步:在PL/SQL下进行测试
SQL测试语句:
insert into King(name) values('刘德华');
存储过程测试:
create or replace procedure insertKing
(
k_name varchar2
)
is
begin
insert into King(name) values(k_name);
commit;
end;
测试:
begin
insertKing('刘德华');
end;