What are the scheduled execution methods in Oracle stored procedures?

Source: Internet
Author: User

The following articles mainly introduce two specific methods for regular execution in Oracle stored procedures. One is to write shell scripts to perform regular execution in the background using crontab correctly, the other is to teach you how to add a job correctly. The following is the specific content of the article.

There are two ways to regularly execute Oracle stored procedures:

1. Write a shell script and use crontab to periodically execute the script in the background.

A) shell script

 
 
  1. Bash-2.03 $ more pr_merge_query_report.sh
  2. #! /Bin/sh
  3. ORACLE_BASE =/oracle/home specifies the environment variable)
  4. ORACLE_HOME =/oracle/home/data
  5. NLS_LANG = american_america.ZHS16GBK
  6. PATH =/usr/local/bin:/usr/sbin:
  7. /Sbin:/usr/local/bin:/opt/EMCpower/bin:
  8. /Etc:/oracle/home/data/bin:/usr/ccs/bin:/usr/openwin/bin:
  9. /Usr/local/bin:/sbin:/usr/bin:
  10. /Usr/local/bin:/usr/local/sbin:/export/home/bss/. db_conf
  11. Export ORACLE_BASE ORACLE_HOME NLS_LANG PATH
  12. Sqlplus-s username/password <
  13. DECLARE
  14. V_date VARCHAR2 (10); V_CODE VARCHAR2 (255); V_MSG VARCHAR2 (255); V_ERR VARCHAR2 (255 );
  15. BEGIN
  16. V_date: = to_char (sysdate, 'yyyymmdd ');
  17. If substr (v_date, 7,2)> = 01 AND substr (v_date, 7,2) <= 04
  18. THEN
  19. ACCOUNT. PR_MERGE_QUERY_REPORT (to_char (SYSDATE, 'yyyymmd')-1, to_char (SYSDATE, 'yyyymmdd'), V_CODE, V_MSG, V_ERR );
  20. ELSE
  21. ACCOUNT. PR_MERGE_QUERY_REPORT (to_char (SYSDATE, 'yyyymmd'), to_char (SYSDATE, 'yyyymmdd'), V_CODE, V_MSG, V_ERR );
  22. End if;
  23. END;
  24. /
  25. Exit;
  26. !

B) crontab

Use crontab-e to edit

30 22 ***/export/home/bss/pr_merge_query_report.sh>/export/home/bss/log/mergequery. log 2> & 1

Time Format: minute hour day month week

2. Add job

With pl/SQL developer, you can easily add regularly executed Oracle stored procedures.

Example:

 
 
  1. begin  
  2. sys.dbms_job.submit(job => :job,  
  3. what => 'RATING.JOB_PRESS;',  
  4. next_date => to_date('01-01-4000', 'dd-mm-yyyy'),  
  5. interval => 'TRUNC(SYSDATE+1)');  
  6. sys.dbms_job.broken(job => :job,  
  7. broken => true,  
  8. next_date => to_date('01-01-4000', 'dd-mm-yyyy'));  
  9. commit;  
  10. end;   

The above content is an introduction to the regular execution methods of Oracle stored procedures. I hope you will get some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.