Oracle自动增长字段
一 建立表
- create table xok.mytable
- (
- id number(2) primary key,
- name char(14),
- sex char(2) check (sex='男' or sex='女'),
- mark varchar2(1000)
- )
二 建立sequence
- create sequence XOK_AUTOINC
- minvalue 1
- start with 1
- increment by 1
- nocache;
三 建立触发器
- create or replace trigger INSERT_FOR_AUTOINC
- before insert on xok.mytable
- for each row
- declare
- -- local variables here
- begin
- select XOK_AUTOINC.nextval into:new.d from dual;
- end insert_for_autoinc;
四 用insert语句测试
- insert into xok.mytable values('','xxx','男','xok.la');
五 查看结果
- select * from xok.mytable;