Prompt Force Delete duplicate Attributes in Entities...

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

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

  -- Validating denormalised property DST.EXPORT_ID
  update ci_datastores@r212 q1
  set q1.EXPORT_ID = null
  where q1.EXPORT_ID is not null
  and not exists ( select null from CI_DATASTORES@r212 q2
	        where q2.ID = q1.EXPORT_ID )
  and q1.application_system_owned_by in ( select ci_appid
	    			          			  from ck_migration_objects
				          				  where ci_stage = 'APPSEL' );			
			

  -- Force Delete duplicate Attributes in Entities...
  for att in
  (
    select att.id id
    from ci_attributes@r212 att
    where att.id < ( select max(att2.id)
 	             from ci_attributes@r212 att2
                     where att.id != att2.id
                     and att.name = att2.name 
                     and att.entity_reference = att2.entity_reference
                   )
    and att.application_system_owned_by in ( select ci_appid
	      				         from ck_migration_objects
						         where ci_stage = 'APPSEL' )
  )
  loop
    ciiutl.delete_element@r212(att.id, 'ATT');

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