PROMPT Updating invalid 'al_id' on ck_application_logic

DECLARE
   bug_no varchar2(8) := 'CK925257';
   newALid number;
BEGIN

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

  for rec in 
  (
    select al.al_id id 
    from sdd_elements@r212 sdd,
         ck_application_logic@r212 al
    where sdd.el_id  = al_id  
    and  sdd.el_elem_owned_by in ( select ci_appid
	    				     from ck_migration_objects
					     where ci_stage = 'APPSEL' )
    union 
    select al.al_id id 
    from sdd_structure_elements@r212 str,
         ck_application_logic@r212 al
    where str.str_id  = al_id  
    and str.str_elem_owned_by in ( select ci_appid
	    		 	           from ck_migration_objects
					     where ci_stage = 'APPSEL' )
  )
  loop
    --  Get new element ID for application logic    
    select   sdd_el_seq.nextval@r212
    into     newALid
    from     sys.dual;

    -- update ck_application_logic with new el_id
    update ck_application_logic@r212 al
    set al_id = newALid
    where al_id = rec.id;     

    -- update cdi_text with new el_id
    update rm_text_lines@r212 txt
    set txt_ref = newALid
    where txt_type in ('ALNOT','ALCODE')
    and txt_ref = 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;
/

 