PROMPT Force delete duplicate Columns

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

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

  for col in
  (
    select col.id id
    from ci_columns@r212 col
    where col.id < ( select max(col2.id)
 	               from ci_columns@r212 col2
                     where col.id != col2.id
                     and col.name = col2.name 
                     and col.table_reference = col2.table_reference
                   )
    and col.application_system_owned_by in ( select ci_appid
	    					         from ck_migration_objects
						         where ci_stage = 'APPSEL' )
  )
  loop
    ciiutl.delete_element@r212(col.id, 'COL');
  
    delete from sdd_elements@r212
    where el_id = col.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;
/
