How can I schedule the execution of a stored procedure in PL/SQL?
One option:
In PL/SQL, you can schedule the execution of a stored procedure using DBMS_SCHEDULER. Here is an example: 1. Create a stored procedure:
CREATE OR REPLACE PROCEDURE my_procedure AS BEGIN– 在这里编写需要执行的代码 END;
Create an assignment:
BEGINDBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_job',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN my_procedure; END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=DAILY; BYHOUR=0; BYMINUTE=0; BYSECOND=0;',
end_date => NULL,
enabled => TRUE,
auto_drop => FALSE
); END;
In the above example, start_date specifies the job’s start time, repeat_interval specifies the job’s repeated execution interval, which is once every day at 0 hours, 0 minutes, and 0 seconds. enabled specifies whether the job is enabled. 3. Run the job:
BEGINDBMS_SCHEDULER.RUN_JOB('my_job'); END;
The above code manually runs a job called my_job. By using DBMS_SCHEDULER, you can schedule the execution of stored procedures according to your own timing and frequency needs.