日期:2014-05-16  浏览次数:20332 次

oracle 中创建自增列的存储过程

1.存储过程如下:

create or replace procedure pr_CreateIdentityColumn
(tablename varchar2,columnname varchar2)
as
strsql varchar2(1000);
begin
strsql := ’create sequence seq_’||tablename||’ minvalue 1 maxvalue 999999999999999999 start with 1 increment by 1 nocache’;
execute immediate strsql;
strsql := ’create or replace trigger trg_’||tablename||’ before insert on ’||tablename||’ for each row begin select seq_’||tablename||’.nextval into :new.’||columnname||’ from dual; end;’;
execute immediate strsql;
end;


我的异常网推荐解决方案:oracle存储过程,http://www.aiyiweb.com/oracle-develop/177537.html