create sequence seq_zizeng increment by 1 start with 1 maxvalue 999999999
--创建序列实现向表t_test前插入数据前id自加1
--创建表
create table t_test
(
country_id varchar2(10),
country_name varchar2(100)
)
--创建触发器
create or replace trigger befo_zizeng before insert on
t_test referencing old as old_values new as new_values for each row
begin
select seq_zizeng.nextval into :new_values.country_id from dual;
end;
-- 插入数据,测试效果,呵呵
insert into t_test(country_name) values('aa');
commit;
insert into t_test(country_name) values('bb');
commit;
insert into t_test(country_name) values('cc');
commit;
insert into t_test(country_name) values('dd');
commit;
insert into t_test(country_name) values('ee');
commit;-------------------------------------------------------
你会发现有五条记录,它们的 country_id字段分别是1,2,3,4,5