1、编写shell脚本,使用crontab在后台定时执行
a) shell脚本
- bash-2.03$ more pr_merge_query_report.sh
- #!/bin/sh
- ORACLE_BASE=/oracle/home (指定环境变量)
- ORACLE_HOME=/oracle/home/data
- NLS_LANG=american_america.ZHS16GBK
- PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:
- /sbin:/usr/local/bin:/opt/EMCpower/bin:
- /etc:/oracle/home/data/bin:/usr/ccs/bin:/usr/openwin/bin:
- /usr/local/bin:/bin:/sbin:/usr/bin:
- /usr/local/bin:/usr/local/sbin:/export/home/bss/.db_conf
- export ORACLE_BASE ORACLE_HOME NLS_LANG PATH
- sqlplus -s username/password <
- DECLARE
- v_date VARCHAR2(10);V_CODE VARCHAR2(255); V_MSG VARCHAR2(255); V_ERR VARCHAR2(255);
- BEGIN
- v_date:=to_char(sysdate,'yyyymmdd');
- if substr(v_date,7,2)>=01 AND substr(v_date,7,2)<=04
- THEN
- ACCOUNT.PR_MERGE_QUERY_REPORT(to_char(SYSDATE,'yyyymm')-1,to_char(SYSDATE,'yyyymmdd'), V_CODE, V_MSG, V_ERR);
- ELSE
- ACCOUNT.PR_MERGE_QUERY_REPORT(to_char(SYSDATE,'yyyymm'),to_char(SYSDATE,'yyyymmdd'),V_CODE, V_MSG, V_ERR);
- END IF;
- END;
- /
- exit;
- !
b) crontab
使用crontab –e编辑
30 22 * * * /export/home/bss/bss/pr_merge_query_report.sh >> /export/home/bss/log/mergequery.log 2>&1
时间格式:分 小时 日 月 星期
2.添加job
使用pl/sql developer 可以很容易添加定时执行的Oracle存储过程
一个例子:
- begin
- sys.dbms_job.submit(job => :job,
- what => 'RATING.JOB_PRESS;',
- next_date => to_date('01-01-4000', 'dd-mm-yyyy'),
- interval => 'TRUNC(SYSDATE+1)');
- sys.dbms_job.broken(job => :job,
- broken => true,
- next_date => to_date('01-01-4000', 'dd-mm-yyyy'));
- commit;
- end;