//Written by Sun Zhenfang 20040903
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;
2、Oracle中执行动态SQL时要显示授权(即使该用户拥有该相关权限)GRANT CREATE ANY SEQUENCE TO "UserName";
GRANT CREATE ANY TRIGGER TO "UserName";
(注重:数据库用户名区分大小写)exec pr_createidentitycolumn('sdspdept','deptid');
exec pr_createidentitycolumn('sdspuser','userid');
exec pr_createidentitycolumn('sdspsysrole','sysroleid');
exec pr_createidentitycolumn('sdspfp','sysfpid');
exec pr_createidentitycolumn('sdspphasemodel','phasemodelid');
exec pr_createidentitycolumn('sdspphase','phaseid');
新闻热点
疑难解答