DBMS_JOB demonstration : DBMS_JOB « System Packages « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE TABLE run_table (message VARCHAR2(40));

Table created.

SQL>
SQL> -- create a procedure to insert rows into the test table:
SQL> CREATE OR REPLACE PROCEDURE p_run_insert IS
  2  BEGIN
  3    INSERT INTO run_table VALUES ('Execution at ' ||  to_char(sysdate, 'dd-mon-yy hh:mi:ss') ) ;
  4    COMMIT ;
  5  END;
  6  /

Procedure created.

SQL>
SQL> -- schedule that procedure to run every 10 seconds (approximately):
SQL> VARIABLE p_jobno number
SQL> BEGIN
  2    DBMS_JOB.SUBMIT (:p_jobno,'P_RUN_INSERT;', SYSDATE,  'SYSDATE + (10/(24*60*60))');
  3    COMMIT;  /* must commit after SUBMIT */
  4  END;
  5  /

PL/SQL procedure successfully completed.

SQL> PRINT p_jobno

   P_JOBNO
----------
       122

SQL>
SQL>
SQL> exec dbms_job.remove(1)
BEGIN dbms_job.remove(1); END;

*
ERROR at line 1:
ORA-23421: job number 1 is not a job in the job queue
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "SYS.DBMS_IJOB", line 529
ORA-06512: at "SYS.DBMS_JOB", line 171
ORA-06512: at line 1


SQL>
SQL> drop table run_table;

Table dropped.

SQL>
SQL>








31.11.DBMS_JOB
31.11.1.DBMS_JOB demonstration
31.11.2.DBMS_JOB.SUBMIT
31.11.3.Submit a job and run
31.11.4.Submit a job and query the user_jobs
31.11.5.Job number
31.11.6.Use dbms_job.submit to call 'execute immediate'
31.11.7.Submit job to change password
31.11.8.Schedule the procedure to run now and every night at 3 AM: