col owner format a10 noprint
col CHILDCOL format a20 noprint
col PARENTCOL format a20 noprint
col CHILD_TABLE format a10 noprint
col PARENT_TABLE format a10 noprint
col constraint_name format a20 noprint
col position format 99 noprint
col check_command format a80
col del_command format a80
set pages 1000 lines 500 term on echo on timi on trimspool on
spool data_cons_check.sql
select b.owner,
b.table_name CHILD_TABLE,
b.column_name CHILDCOL,
c.table_name PARENT_TABLE,
c.column_name PARENTCOL,
a.constraint_name,
b.position,
a.status,
'select ' || b.column_name || ' from ' || b.table_name || ' MINUS select ' || c.column_name || ' from ' || c.table_name || ';' check_command,
'delete from ' || b.table_name || ' where ' || b.column_name || ' in (' || 'select ' || b.column_name || ' from ' || b.table_name || ' MINUS select ' || c.column_name || ' from ' || c.table_name || ');' delete_command
from all_cons_columns b,
all_cons_columns c,
all_constraints a
where b.constraint_name = a.constraint_name
and a.owner = b.owner
and b.position = c.position
and c.constraint_name = a.r_constraint_name
and c.owner = a.r_owner
and a.constraint_type = 'R'
and c.owner like case when upper('&OWNER_NAME') is null then '%'
else upper('&OWNER_NAME') end
and c.table_name like case when upper('&PARENT_TABLE_NAME') is null then '%'
else upper('&PARENT_TABLE_NAME') end
and b.table_name like case when upper('&CHILD_TABLE_NAME') is null then '%'
else upper('&CHILD_TABLE_NAME') end
order by 1,2,3,4,6
/
spoo off