You can avoid PL/SQL code and several dynamically constructed alter table
statements. In order to disable all foreign keys that depend on a particular table's primary key, simply disable primary key with cascade
clause and then re-enable(if you need to) it again.
Here is an example:
--drop table t3;
--drop table t2;
--drop table t1;
create table t1(c1 number primary key);
create table t2(c1 number references t1(c1));
create table t3(c1 number references t1(c1));
select table_name
, constraint_type
, status
from user_constraints
where table_name in ('T1','T2', 'T3')
TABLE C STATUS
----- - ----------
T2 R ENABLED
T1 P ENABLED
T3 R ENABLED
3 rows selected.
Disabling foreign keys:
alter table t1 disable primary key cascade;
alter table t1 enable primary key;
Result:
select table_name
, constraint_type
, status
from user_constraints
where table_name in ('T1','T2', 'T3')
TABLE C STATUS
----- - ----------
T2 R DISABLED
T1 P ENABLED
T3 R DISABLED
3 rows selected.
Note: It's not possible to enable all foreign key constraints again in cascade mode. It'd have to be done manually.