--利用存储过程动态创建表及基于该表的触发器
--1、授权
grant create any sequence to scott;
grant create any sequence to scott;
grant select any sequence to scott;
grant create any trigger to scott;
--2、存储过程
create or replace procedure test_trigger
as
v_name varchar2(100);
v_Sql varchar2(1000);
begin
select to_char(sysdate,'yyyymmdd') into v_name from dual;
v_Sql:='create table tt'||v_name||'(id number(16),nn varchar2(100))';
execute immediate v_sql;
v_Sql:='create sequence seq_'||v_name||' start with 1';
execute immediate v_sql;
v_sql:='create or replace trigger trig_'||v_name||' before insert on tt'||v_name||' for each row begin select seq_'||v_name||'.nextval into :new.id from dual; end;';
execute immediate v_sql;
/*exception
when others then
null;*/
end;
--注意,要是存储过程执行没有问题,但有没有达到预想的结果,可以先把EXCEPTION代码端注释掉,让错误信息抛出来看看到底是什么错误