通过序列和触发器的方式实现列自增,脚本如下:
Create table test(id int, v carchar(1000));
Create sequence seq start with 1;
Create or replace trigger test_insert before insert on test for each row
Begin
Select seq.nextval into:new.id from dual;
End;
/
Insert into test values(1,’123123123’);
Insert into test values(1,’123123123’);
Select * from test order by id;
结果如下:
1 123123123
2 123123123