Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 
Connected as focususer

SQL> 
SQL> --JOB 需要在命令行执行;
SQL>  --抽数job
SQL>   CREATE OR REPLACE PROCEDURE RPT
  2  --业务
  3   AS
  4    v_time    VARCHAR2(20); /*运行当天*/
  5    v_timeold VARCHAR2(20); /*运行前一天*/
  6  
  7  BEGIN
  8    --查询系统时间
  9    select to_char(sysdate, 'yyyy-mm-dd'), to_char(sysdate - 1, 'yyyy-mm-dd')
 10      into v_time, v_timeold
 11      from dual;
47         commit;
 48    --异常情况处理
 49  
 50  EXCEPTION
 51    WHEN OTHERS THEN
 52      ROLLBACK;
 53  END RPT;
 54  /

Procedure created
SQL> --新建JOB
SQL>   --SM_MANUAL_SM_LIST的job
SQL> variable   job2  number;
SQL> begin
  2    sys.dbms_job.submit(:job2,
  3                        'RPT;',
  4                        to_date('22-03-2016 06:00:00',
  5                                'dd-mm-yyyy hh24:mi:ss'),
  6                        'TRUNC(SYSDATE+1,''DD'')+360/1440');
  7    commit;
  8  end;
  9  /

PL/SQL procedure successfully completed
job2
---------
69
SQL> commit;

Commit complete
SQL> --启动JOB
SQL> begin
  2    sys.dbms_job.run(:job2);
  3    end;
  4  /

PL/SQL procedure successfully completed
job2
---------
69
SQL> --移除JOB
SQL> begin
  2    sys.dbms_job.remove(:job2);
  3    end;
  4  /

PL/SQL procedure successfully completed
job2
---------
69

 

posted on 2017-02-19 19:23  塞北夜莺  阅读(292)  评论(0编辑  收藏  举报