PROMPT Force delete duplicate Dataflows

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

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

  for dataflow in
  (
    select dfl.id id
    from ci_dataflows@r212 dfl
    where dfl.id < ( select max(dfl2.id)
    	               from ci_dataflows@r212 dfl2
                     where dfl.id != dfl2.id
                     and dfl.name = dfl2.name                  
			   and dfl.datastore_source_reference = dfl2.datastore_source_reference
			   and dfl.datastore_dest_reference = dfl2.datastore_dest_reference
                   )
    and dfl.application_system_owned_by in ( select ci_appid
	    	  			               from ck_migration_objects
						         where ci_stage = 'APPSEL' )
  )
  loop
    ciiutl.delete_element@r212(dataflow.id, 'DFL');

    delete from sdd_elements@r212
    where el_id = dataflow.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;
/
