PROMPT Updating invalid 'id' for element type 'APPDOM'

DECLARE
   bug_no varchar2(8) := 'CK946906';
   newAPPDOMid number;

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


  -- Validating denormalised property BUN.EXPORT_ID
  update ci_business_units@r212 q1
  set q1.EXPORT_ID = null
  where q1.EXPORT_ID is not null
  and not exists ( select null from CI_BUSINESS_UNITS@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' );
  
  -- Validating denormalised property FUN.EXPORT_ID
  update ci_functions@r212 q1
  set q1.EXPORT_ID = null
  where q1.EXPORT_ID is not null
  and not exists ( select null from CI_FUNCTIONS@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' );


  -- Updating invalid 'id' for element type 'APPDOM'
  for rec in 
  (
    select str.str_id id 
    from sdd_elements@r212 sdd,
         sdd_structure_elements@r212 str
    where sdd.el_type_of = 'DOM' 
    and sdd.el_id = str.str_id
    and str.str_type_of = 'APPDOM'
    and sdd.el_elem_owned_by in ( select ci_appid
	    			          from ck_migration_objects
				          where ci_stage = 'APPSEL' )
  )
  loop
    --  Get new element ID for APPDOM
    select   sdd_el_seq.nextval@r212
    into     newAPPDOMid
    from     sys.dual;

    -- update sdd_structure_elements with new el_id
    update sdd_structure_elements@r212
    set str_id = newAPPDOMid
    where str_id = rec.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;
/



 