drop table t_city; create table t_city(city_id number(12),city_name varchar(30)); drop sequence s_city_id; create sequence s_city_id increment by 1 start with 1 maxvalue 999999999; create or replace trigger bef_ins_t_city before insert on t_city referencing old as old new as new for each row BEGIN select s_city_id.nextval into :new.city_id from dual; END bef_ins_t_city;然后: insert into t_city(city_name) values ('qingdao'); insert into t_city(city_name) values ('yantai');
可以使用序列和触发器来实现
help me!
09:11:39 2 id NUMBER(5) PRIMARY KEY,
09:11:39 3 name VARCHAR2(20)
09:11:39 4 );表已创建。实际:3034
09:11:42 SQL> create sequence s_id increment by 1 start with 1 maxvalue 99999序列已创建。实际:70
09:11:42 SQL> insert into students values(s_id.nextval,'n1');已创建 1 行。实际:180
09:11:42 SQL> insert into students values(s_id.nextval,'n2');已创建 1 行。实际:40
09:11:42 SQL> insert into students values(s_id.nextval,'n3');已创建 1 行。实际:30
09:11:44 SQL> select * from students; ID NAME
--------- --------------------
1 n1
2 n2
3 n3实际:50
您好:
如果自增长列(序列值)达到最大值99999该怎么办???
则自动返回到最小值缺省是nocycle,到最大则不能再取了
所以尽量创建的足够大
create table t_city(city_id number(12),city_name varchar(30));
drop sequence s_city_id;
create sequence s_city_id increment by 1 start with 1 maxvalue 999999999;
create or replace trigger bef_ins_t_city before insert on t_city referencing old as old new as new for each row
BEGIN
select s_city_id.nextval into :new.city_id from dual;
END bef_ins_t_city;然后:
insert into t_city(city_name) values ('qingdao');
insert into t_city(city_name) values ('yantai');
就可以看出city_id字段是自动增加的~!
在一个脚本中怎么样写多个触发器?
请高手赐教~~~~~~~~
http://expert.csdn.net/Expert/topic/1553/1553712.xml?temp=.0151636