Example—Scheduling Utilities To Run Automatically
In order to execute the following sample SQL file, as user aptare on a Linux system or on a Windows system as an Administrator who is a member of the ORA_DBA group execute the following:
sqlplus portal/portal_password @setup_ora_job.sql
The following example uses two methods:
moveOracleClients | The name you want to assign to this job you are defining. |
MoveOrCopyClients | The utility you are calling along with the parameters you are passing. |
Note: The parameters passed to the moveOrCopyClients method which must be quoted actually have two single quotes. The two single quotes is the standard Oracle syntax to incorporate a literal quote within an already quoted string.
Sample .sql file (setup_ora_job.sql) to set up an automatic job
SET SERVEROUTPUT ON
SET ECHO OFF
DECLARE
jobNo user_jobs.job%TYPE := NULL;
BEGIN
----------------------------------------------------------------------
-- Move new clients whose server name ends with 'ORA' into the 'database' host group
-- Frequency: Every day at 5am (Portal Time)
----------------------------------------------------------------------
jobNo := dba_package.getDatabaseJobID('moveOracleClients');
IF (jobNo IS NOT NULL AND jobNo != 0) THEN
DBMS_OUTPUT.put_line('moveOracleClients exists and will first be removed before adding a new version');
DBMS_JOB.REMOVE(jobNo);
END IF;
DBMS_JOB.SUBMIT(
job => jobNo,
what => 'server_mgmt_pkg.moveOrCopyClients(''/Aptare'',''/Aptare/database'',''*ORA'', 1);', -- What to run
next_date => SYSDATE + (5/24), -- First run is 5am server time
interval => 'TRUNC(SYSDATE+1,''DD'') + (5/24)'); -- Next run is 5am each subsequent day
DBMS_OUTPUT.put_line('moveOracleClients job set to run at 5am every day');
COMMIT;
END;
/
quit;