PROMPT Force delete duplicate Index Entries (column appears more than once)

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

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

  for indcol in
  (
    select indcol.id id
    from ci_index_entries@r212 indcol
    where indcol.id < ( select max(indcol2.id)
 			      from ci_index_entries@r212 indcol2
                        where indcol.id != indcol2.id
                        and indcol.column_reference = indcol2.column_reference 
                        and indcol.relation_index_reference = indcol2.relation_index_reference
                      )
     and indcol.application_system_owned_by in ( select ci_appid
	    					             from ck_migration_objects
						             where ci_stage = 'APPSEL' )
  )
  loop
    ciiutl.delete_element@r212(indcol.id, 'INDCOL');
  
    delete from sdd_structure_elements@r212
    where str_id = indcol.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;
/
