Search notes:

Oracle: Capture a job's produced output

Create the credential
begin
  dbms_credential.create_credential(
      credential_name => 'RENES_CREDENTIALS',
      username        => 'rene',
      password        => '…'
  );
end;
/
… to run the PowerShell command get-date:
begin
   dbms_scheduler.create_job (
      job_name            => 'RUN_POWERSHELL_SCRIPT',
      job_type            => 'executable',
      job_action          => 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe',
      credential_name     => 'RENES_CREDENTIALS',
      enabled             =>  false,
      auto_drop           =>  true,
      number_of_arguments =>  3
   );

   dbms_scheduler.set_job_argument_value(
      job_name            => 'RUN_POWERSHELL_SCRIPT',
      argument_position   =>  1,
      argument_value      => '-noProfile'
   );

   dbms_scheduler.set_job_argument_value(
      job_name            => 'RUN_POWERSHELL_SCRIPT',
      argument_position   =>  2,
      argument_value      => '-c'
   );

   dbms_scheduler.set_job_argument_value(
      job_name            => 'RUN_POWERSHELL_SCRIPT',
      argument_position   =>  3,
      argument_value      => 'get-date'
   );

   dbms_scheduler.enable('RUN_POWERSHELL_SCRIPT');

end;
/
The output of the script/executable is stored in output (varchar2) and binary_output (blob) in dba_scheduler_job_run_details:
select
   status,
   log_date,
   output,
   binary_output
from
   user_scheduler_job_run_details
where
   job_name = 'RUN_POWERSHELL_SCRIPT';
Cleaning up:
begin
   dbms_credential.drop_credential('RENES_CREDENTIALS');

   dbms_scheduler.purge_log (
      job_name    => 'RUN_POWERSHELL_SCRIPT'
   );

end;
/

See also

This example is a variation of executing a PowerShell script with Oracle's scheduler.

Index