PROMPT Populate missing APPLICATION_SYSTEM_OWNED_BY on Constraint Usages...

DECLARE
   bug_no varchar2(9):= 'CK942743';
BEGIN

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

  update ci_constraint_usages@r212 cnu
  set cnu.application_system_owned_by = ( select mti.application_system_owned_by		
						  				  from ci_module_detail_table_usages@r212 mti
						     			  where cnu.table_usage_reference = mti.id
						     			  and mti.application_system_owned_by in ( select ci_appid
														    		  	    	   from ck_migration_objects
													    						   where ci_stage = 'APPSEL' )
										)
  where cnu.application_system_owned_by is null;

  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;
/
