Use DBMS_SCHEDULER to run SQL on a schedule and export results automatically.
Automation frees analysts from manual exports, guarantees timely delivery, and creates audit-ready, reproducible output.
Create a scheduler job that runs a stored procedure or SQL script, then write the result set to a file or table.
You need CREATE JOB, CREATE PROCEDURE, and WRITE access on an Oracle DIRECTORY object that points to the file system path where the report will be written.
Use DBMS_SCHEDULER.CREATE_JOB with parameters for job name, schedule, job action, and destination.Optionally, use DBMS_SCHEDULER.ENABLE to activate the job.
Inside the job action, open a UTL_FILE handle to the DIRECTORY, LOOP through the cursor that selects your data, and write each row as comma-separated text.
The example below creates a procedure export_daily_revenue
that selects yesterday’s revenue from Orders
and writes it to daily_revenue_YYYYMMDD.csv
.A scheduler job then runs the procedure at 02:00 every day.
Log errors with DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
, keep procedures idempotent, and store generated files in a version-controlled bucket or table for traceability.
See the section below for pitfalls such as wrong job_type
or missing directory grants.
Use DBMS_SCHEDULER.SET_ATTRIBUTE
to update repeat_interval
or start_date
without recreating the job.
.
Yes. After writing the file, call UTL_SMTP or an APEX_MAIL package to attach and send the report.
Use DBMS_SCHEDULER.DISABLE('job_name'). Re-enable later with DBMS_SCHEDULER.ENABLE('job_name').
DBMS_JOB works but is deprecated; DBMS_SCHEDULER offers more control, calendars, and logging.