一。oracle自增列
可以配合序列和触发器实现
create table A_Test2(
empid number,--雇员ID
depid number,--部门ID
area varchar(20),--区域
s_id varchar(20) --测试列
);
insert into A_Test2(empid,depid,area)values(3,1,'china');
insert into A_Test2(empid,depid,area)values(2,1,'china');
insert into A_Test2(empid,depid,area)values(3,2,'china');
insert into A_Test2(empid,depid,area)values(3,3,'china');
select * from A_Test2
create sequence a_test2_sequence
increment by 1
start with 1
maxvalue 9999999
nocycle
cache 10;
create or replace trigger a_test2_trigger
before insert
on a_test2
for each row
begin
select a_test2_sequence.nextval into :new.s_idfrom dual;
end;
insert into a_test2(empid,depid,area)values(7,5,'china');
-------
要说的是 :old 与:new的区别:
顾名思义,new是新插入的数据,old是原来的数据
insert只会有new,代表着要插入的新记录
delete只会有old,代表着要删除的记录
update由于执行的是先删除旧的记录,再插入新的记录,因此new和old都会有,且含义与上面的相同
-----------------------------------------------------------------------------------------------------------------------------------------------
二。游标
http://www.cnblogs.com/huyong/archive/2011/05/04/2036377.html