在数据库中执行:
第一步:创建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;
/
程序中直接插入数据,与插入值无关
第一步:创建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;
/
程序中直接插入数据,与插入值无关
解决方案 »
- occi vs otl,请c++经验的进来说说
- 用存储过程还是触发器
- 有关left join的问题
- 高手帮忙解决oracle一个行列转换的问题!
- 请教一条sql语句的写法
- 关于case的问题
- Oracle8i在unix下持续13天占CPU 70%,影响应用系统访问速度,请大家出招帮忙解决
- 请教各位高手一个关于oracle10g silent安装的问题啊,主管催的急死了,给分100
- 怎样实现这种效果?
- 请教大家一个绝对多难题!急!!!!!!!!!(还是那道题)
- 简单的表空间问题,来者有分!
- 在asp 中为何我用oracle 的oledb不可以连上?(win200server + oracle8.05)
你要先建一个SEQUENCT ,如CREATE SEQUENCT 序列名 START WITH 起始值 NOCACHE[CACHE int];
建好后,你就可以在表操作中使用它,如:
insert into table_a (column_1) values (序列名(nextval));
每调用一次,序列就自动增加一,或按CACHE 的int 值变化.
在insert into 时 调用序列发生器
create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
然后再程序里,当向表插入数据时,要自动加一的字段的值用s_country_id.nextval代替就可以了。
insert into tablename (id,col1,col2) values (s_country_id.nextval,'sdfsdf','asdf');
其中id是要自动加一的字段。