PROMPT Force delete duplicate Constraint Usages

DECLARE
   bug_no varchar2(8) := 'CK917290';
BEGIN

  update ck_migration_objects set ci_created = 'N' where ci_stage = 'CKPREMIG' and ci_name = bug_no;

  for cnu in
  (
    select cnu.id id
    from ci_constraint_usages@r212 cnu
    where cnu.id < ( select max(cnu2.id)
 			   from  ci_constraint_usages@r212 cnu2
                     where cnu.id != cnu2.id
                     and   cnu.constraint_reference = cnu2.constraint_reference 
                     and   cnu.table_usage_reference = cnu2.table_usage_reference
                   )
    and cnu.application_system_owned_by in ( select ci_appid
	    				               from ck_migration_objects
						         where ci_stage = 'APPSEL' )
  )
  loop
    ciiutl.delete_element@r212(cnu.id, 'CNU');
  
    delete from sdd_elements@r212
    where el_id = cnu.id;
	     
  end loop;

  update ck_migration_objects set ci_created = 'Y' where ci_stage = 'CKPREMIG' and ci_name = bug_no;
   
  commit;
  
EXCEPTION 
  when others then
     dbms_output.put_line (' ** Exception Raised ** ');
     dbms_output.put_line ('...ERROR: '||substrb(sqlerrm, 1, 200));
     raise;
	 
end;
/
