DBMS_SCHEDULER lets you run SQL or PL/SQL automatically at defined times or intervals.
Automating recurring SQL eliminates manual execution, ensures reports are refreshed on time, and frees developers for high-value work. Jobs created with DBMS_SCHEDULER
run inside the database, inherit server resources, and can log output for auditing.
Grant CREATE JOB
and, if needed, MANAGE SCHEDULER
. Developers without DBA rights can still create jobs inside their schema when these privileges are enabled.
Use DBMS_SCHEDULER.CREATE_JOB
with job_name
, job_type
, job_action
, and schedule_name
(or inline schedule). Optionally set enabled => TRUE
to start immediately.
Create a reporting table, then schedule an INSERT INTO
that copies aggregated data every hour:
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name => 'hourly_sales_totals',
job_type => 'PLSQL_BLOCK',
job_action => 'INSERT INTO sales_totals
SELECT TRUNC(SYSDATE, ''HH''), SUM(total_amount)
FROM Orders
GROUP BY TRUNC(order_date, ''HH'');',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=HOURLY',
enabled => TRUE);
END;
/
Define a named schedule once, then attach it to multiple jobs with schedule_name
. Example: DBMS_SCHEDULER.CREATE_SCHEDULE
to build hourly_interval
.
Wrap your logic in a stored procedure. In CREATE_JOB
set job_type => 'STORED_PROCEDURE'
and job_action => 'pkg_reports.gen_customer_kpi'
. Arguments are defined inside the procedure signature.
Query USER_SCHEDULER_JOBS
and USER_SCHEDULER_JOB_RUN_DETAILS
. Use DBMS_SCHEDULER.RUN_JOB
, STOP_JOB
, and DROP_JOB
for control.
Keep job names descriptive, log errors with JOB_CLASS
, restrict privileges, and avoid heavy logic in anonymous blocks; call procedures instead.
Missing grants: Without CREATE JOB
your script fails. Ask a DBA to grant it.
Forgetting time zone: Use SYSTIMESTAMP
and specify repeat_interval
in calendar syntax to prevent DST surprises.
Yes—set job_type = 'EXECUTABLE'
and give the database host user permission to run the file.
Run DBMS_SCHEDULER.DISABLE('job_name')
. Re-enable with ENABLE
.
It is supported but deprecated. New code should use DBMS_SCHEDULER
for richer features and time-zone awareness.
Yes, it is included in Standard and Enterprise editions starting with Oracle 10g.
Yes—create a chain with DBMS_SCHEDULER.CREATE_CHAIN
and define step dependencies.
Assign a log_destination
or read USER_SCHEDULER_JOB_LOG
for run history.