我以前是用Sql server 的 在创建表的时候 对要自增的字段 直接就 identity,
现在换了公司 用oracle了 但这个自增我没用明白, 后来查了下 说要先创建序列 然后触发器 在调用 可我还是没弄明白所以麻烦各位GG,JJ了 帮个忙
怎样创建序列
怎样创建触发器 并能调用 序列
怎样在VS2008中 调用触发器
谢谢了
最好详细点...谢谢
现在换了公司 用oracle了 但这个自增我没用明白, 后来查了下 说要先创建序列 然后触发器 在调用 可我还是没弄明白所以麻烦各位GG,JJ了 帮个忙
怎样创建序列
怎样创建触发器 并能调用 序列
怎样在VS2008中 调用触发器
谢谢了
最好详细点...谢谢
SQL> create sequence sq1 start with 1;Sequence created.
SQL> create table t_1(f1 number(10), f2 number(10));Table created.
SQL> create or replace trigger tr_t_1
2 before insert on t_1
3 for each row
4 begin
5 select sq1.nextval into :new.f1 from dual;
6 end;
7 /Trigger created.SQL> select * from t_1;no rows selectedSQL> insert into t_1(f2) values(10);1 row created.SQL> select * from t_1; F1 F2
---------- ----------
1 10SQL> insert into t_1(f2) values(20);1 row created.SQL> select * from t_1; F1 F2
---------- ----------
1 10
2 20方式二:不用触发器
SQL> create sequence sq2 start with 1;Sequence created.SQL> create table t_2(f1 number(10), f2 number(10));Table created.
SQL> insert into t_2 values(sq2.nextval, 10); 1 row created.SQL> insert into t_2 values(sq2.nextval, 20);1 row created.SQL> select * from t_2; F1 F2
---------- ----------
1 10
2 20