Tuesday, April 22, 2008

Procedure To ENABLE and DISABLE Triggers on a Schema level

CREATE or replace procedure enable_triggers as
v_tablename varchar2(100);
v_query1 varchar2(100);
v_query2 varchar2(100);
v_query varchar2(100);

-- A cursor is used to fetch all the Tables in the Schema
cursor v_cursor is
select table_name from User_tables;

v_row v_cursor%rowtype;

begin

open v_cursor;
loop
fetch v_cursor into v_row;
if v_cursor%notfound then
exit;
end if;

v_tablename := v_row.table_name;

v_query1:=\'alter table\';

-- For disabling the triggers on the tables ,
-- the following line can be changed as \" v_query2:=\'disable all triggers\';\"
v_query2:=\'enable all triggers\';
v_query:=v_query1||\' \'||v_tablename||\' \'||v_query2;
dbms_output.put_line(v_query);
execute immediate ( v_query);

end loop;

close v_cursor;
end;
/


--- Execute the Procedure ------
EXECUTE ENABLE_TRIGGERS;

No comments: