PROMPT Updating invalid values for 'source_entity_derived_from' to null

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

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


   update ci_columns@r212
   set source_entity_derived_from = null
   where source_entity_derived_from is not null
   and not exists ( select 1
                    from ci_entities@r212
                    where id = source_entity_derived_from )
   and application_system_owned_by in ( select ci_appid
	 			                from ck_migration_objects
						    where ci_stage = 'APPSEL' );
					

   -- Updating invalid values for 'source_rel_entity' to null
   update ci_columns@r212
   set source_rel_entity = null
   where source_rel_entity is not null
   and not exists ( select 1
                    from ci_entities@r212
                   where id = source_rel_entity )
   and application_system_owned_by in ( select ci_appid
  					          from ck_migration_objects
						    where ci_stage = 'APPSEL' );
				    
  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;
/
