第一步:创建SEQUENCE
create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
第二步:创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE
create or replace trigger bef_ins_t_country_define
before insert on t_country_define
referencing old as old new as new for each row
begin
select s_country_id.nextval into :new.country_id from dual;
end;
/
create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
第二步:创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE
create or replace trigger bef_ins_t_country_define
before insert on t_country_define
referencing old as old new as new for each row
begin
select s_country_id.nextval into :new.country_id from dual;
end;
/
INSERT INTO TBNAME VALUES(s_country_id.NEXTVAL,...);
1.首先创建 sequence
create sequence seqmax increment by 1
2.使用方法
select seqmax.nextval ID from dual
就得到了一个ID
如果把这个语句放在 触发器中,就可以实现和mssql 的自动增加ID相同的功能!
create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
第二步:创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE
create or replace trigger bef_ins_t_country_define
before insert on t_country_define
referencing old as old new as new for each row
begin
--select s_country_id.nextval into :new.country_id from dual;
INSERT INTO TBNAME VALUES(s_country_id.NEXTVAL,...);
end;
是什么意思呢?
second : create a triggers...before you insert a value into your table ...
create or replace trigger *****_TRIGGER before insert on ******* for each row
begin Select **********_SEQUENCE.nextval into :new.***** from dual; end;
create sequence sequ increment by 1 start with 1
然后在插入的时候调用使用 sequ.nextval