oracle chain

Posted jzssuanfa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle chain相关的知识,希望对你有一定的参考价值。



[[email protected] dbs]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Tue May 6 13:02:41 2014


Copyright (c) 1982, 2005, Oracle.  All rights reserved.




Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options


/* 创建測试用户tyger 赋予权限 */


[email protected]>drop user tyger cascade;


User dropped.


[email protected]>create user tyger identified by tyger account unlock;


User created.


[email protected]>grant connect,resource to tyger;


Grant succeeded.


[email protected]>conn tyger/tyger
Connected.


/* 创建序列 seq_chain 以及測试表 tab1  tab2  tab3 */


[email protected]>create sequence seq_chain;


Sequence created.


[email protected]>create table tab1(id number(5),cdate date,sdate date default sysdate);


Table created.


[email protected]>create table tab2(id number(5),cdate date,sdate date default sysdate);


Table created.


[email protected]>create table tab3(id number(5),cdate date,sdate date default sysdate);


Table created.


/* 创建program 报错权限不足  */


[email protected]>begin
DBMS_SCHEDULER.CREATE_PROGRAM (
   program_name             => ‘CHAIN_P1‘,
   program_type             => ‘PLSQL_BLOCK‘,
   program_action           => ‘begin
        execute immediate ‘‘insert into tab1(id,cdate)
                values(seq_chain.nextval,add_months(sysdate,seq_chain.currval))‘‘;
        end;‘,
   enabled                  => true);
end;
/
  2    3    4    5    6    7    8    9   10   11  
*
ERROR at line 1:
ORA-27486: insufficient privileges
ORA-06512: at "SYS.DBMS_ISCHED", line 5
ORA-06512: at "SYS.DBMS_SCHEDULER", line 30
ORA-06512: at line 2


 /* 赋予必要权限 以及接下去实验须要的权限 */


[email protected]>conn / as sysdba
Connected.
[email protected]>grant create job to tyger;


Grant succeeded.


[email protected]>grant create evaluation context to tyger;


Grant succeeded.


[email protected]>grant create rule set to tyger;


Grant succeeded.


[email protected]>grant create rule to tyger;


Grant succeeded.


/* 创建program  */


[email protected]>conn tyger/tyger
Connected.

[email protected]>begin
DBMS_SCHEDULER.CREATE_PROGRAM (
   program_name             => ‘CHAIN_P1‘,
   program_type             => ‘PLSQL_BLOCK‘,
   program_action           => ‘begin
        execute immediate ‘‘insert into tab1(id,cdate)
                values(seq_chain.nextval,add_months(sysdate,seq_chain.currval))‘‘;
        end;‘,
   enabled                  => true);
end;
/
  2    3    4    5    6    7    8    9   10   11  
PL/SQL procedure successfully completed.



[email protected]>begin
DBMS_SCHEDULER.CREATE_PROGRAM (
   program_name             => ‘chain_step2‘,
   program_type             => ‘PLSQL_BLOCK‘,
   program_action           => ‘begin
        execute immediate ‘‘insert into tab2(id,cdate)
                values(seq_chain.nextval,add_months(sysdate,seq_chain.currval))‘‘;
        end;‘,
   enabled                  => true);
end;
/
  2    3    4    5    6    7    8    9   10   11  
PL/SQL procedure successfully completed.


[email protected]>begin
DBMS_SCHEDULER.CREATE_PROGRAM (
   program_name             => ‘CHAIN_P3‘,
   program_type             => ‘PLSQL_BLOCK‘,
   program_action           => ‘begin
        execute immediate ‘‘insert into tab3(id,cdate)
                values(seq_chain.nextval,add_months(sysdate,seq_chain.currval))‘‘;
        end;‘,
   enabled                  => true);
end;
/
  2    3    4    5    6    7    8    9   10   11  
PL/SQL procedure successfully completed.





/* 创建链tyger_chain */


[email protected]>exec dbms_scheduler.create_chain(‘tyger_chain‘);


PL/SQL procedure successfully completed.


[email protected]>select chain_name from user_scheduler_chains;


CHAIN_NAME
------------------------------
TYGER_CHAIN




/* 创建chain step 

为链TYGER_CHAIN 加入step ,能够一个一个的加入,也能够一下所有加入 */


[email protected]>
[email protected]>begin 
dbms_scheduler.define_chain_step(
   chain_name =>‘TYGER_CHAIN‘,
   step_name =>‘CHAIN_STEP1‘,
   program_name => ‘CHAIN_P1‘);
end;
/
  2    3    4    5    6    7  
PL/SQL procedure successfully completed.


[email protected]>begin
 dbms_scheduler.define_chain_step(
    chain_name =>‘TYGER_CHAIN‘,
     step_name =>‘CHAIN_STEP2‘,
     program_name => ‘chain_step2‘);
 dbms_scheduler.define_chain_step(
    chain_name =>‘TYGER_CHAIN‘,
     step_name =>‘chain_step3‘,
    program_name => ‘CHAIN_P3‘);
 end;
 /
  2    3    4    5    6    7    8    9   10   11  
PL/SQL procedure successfully completed.


/* 查看创建的step 是否成功 */


[email protected]>col chain_name for a16
[email protected]>col step_name for a16
[email protected]>col program_name for a16
[email protected]>select chain_name,step_name,program_name  
  2  from user_scheduler_chain_steps;


CHAIN_NAME       STEP_NAME        PROGRAM_NAME
---------------- ---------------- ----------------
TYGER_CHAIN CHAIN_STEP1 CHAIN_P1
TYGER_CHAIN CHAIN_STEP2 CHAIN_P2
TYGER_CHAIN CHAIN_STEP3 CHAIN_P3




/* 为链创建规则 */

/* 规则:首先运行 chain_step1,成功完毕后运行 chain_step2 ,成功完毕后运行 chain_step3,成功完毕后,结束。 */


[email protected]>
[email protected]>begin
DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
   chain_name              => ‘TYGER_CHAIN‘,
   condition               => ‘true‘,
   action                  => ‘start CHAIN_STEP1‘,
   rule_name               => ‘rule_01‘);
DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
   chain_name              => ‘TYGER_CHAIN‘,
   condition               => ‘CHAIN_STEP1 SUCCEEDED‘,
   action                  => ‘start chain_step2‘,
   rule_name               => ‘rule_02‘);
DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
   chain_name              => ‘TYGER_CHAIN‘,
   condition               => ‘chain_step2 SUCCEEDED‘,
   action                  => ‘start chain_step3‘,
   rule_name               => ‘rule_03‘);
DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
   chain_name              => ‘TYGER_CHAIN‘,
   condition               => ‘chain_step3 SUCCEEDED‘,
   action                  => ‘END 0‘,
   rule_name               => ‘rule_04‘);
END;
/
  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23  
PL/SQL procedure successfully completed.


/* 启用链 tyger_chain */


[email protected]>exec dbms_scheduler.enable(‘TYGER_CHAIN‘);


PL/SQL procedure successfully completed.


手动执行链 tyger_chain


[email protected]>begin
DBMS_SCHEDULER.RUN_CHAIN (
   chain_name               =>‘TYGER_CHAIN‘,
   start_steps              =>‘CHAIN_STEP1‘);
end;
/
  2    3    4    5    6  
PL/SQL procedure successfully completed.


/* 验证
是不是依照我们设计的规则 tab1 -> tab2 -> tab3 ->exit 完毕的。

*/


[email protected]>alter session set nls_date_format=‘yyyy-mm-dd hh24:mi:ss‘;


Session altered.


[email protected]>select * from tab1;


        ID CDATE               SDATE
---------- ------------------- -------------------
         1 2014-06-06 13:14:24 2014-05-06 13:14:24


[email protected]>select * from tab2;


        ID CDATE               SDATE
---------- ------------------- -------------------
         2 2014-07-06 13:14:25 2014-05-06 13:14:25


[email protected]>select * from tab3;


        ID CDATE               SDATE
---------- ------------------- -------------------
         3 2014-08-06 13:14:25 2014-05-06 13:14:25


[email protected]>





































































































































































































































































































































以上是关于oracle chain的主要内容,如果未能解决你的问题,请参考以下文章

windows安装oracle76%卡了

oracle 语法

oracle 是怎么收费的?

oracle的数据怎么发送到接口

oracle 查版本号,oracle怎样查版本

如何下载oracle11g