Bo's Oracle Station

查看: 2220|回复: 0

第67次:2014-11-18

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2014-11-19 16:37:04 | 显示全部楼层 |阅读模式
本帖最后由 botang 于 2014-11-27 16:04 编辑

2014-11-18-CHAIN.sql:
  1. create or replace procedure  proc05317
  2. is
  3. begin
  4.    update employees set salary=salary+0.1 where employee_id=100;
  5.    commit;
  6. end;

  7. select * from user_scheduler_schedules;

  8. select  * from scheduler_test;

  9. drop table scheduler_test;

  10. CREATE TABLE scheduler_test (

  11.   id            NUMBER(10)    NOT NULL,

  12.   description   VARCHAR2(20)  NOT NULL,

  13.   created_date  DATE          NOT NULL,

  14.   CONSTRAINT scheduler_test_pk PRIMARY KEY (id)

  15. );






  16. select  * from scheduler_test;

  17. select  scheduler_test_seq.nextval from dual;

  18. drop sequence scheduler_test_seq;

  19. CREATE SEQUENCE scheduler_test_seq;

  20. BEGIN

  21.   DBMS_SCHEDULER.create_program (

  22.     program_name   => 'test_program_1',

  23.     program_type   => 'PLSQL_BLOCK',

  24.     program_action => 'BEGIN

  25.                          INSERT INTO scheduler_test (id, description, created_date)

  26.                          VALUES (scheduler_test_seq.NEXTVAL, ''test_program_1'', SYSDATE);

  27.                          COMMIT;

  28.                        END;',

  29.     enabled        => TRUE,

  30.     comments       => 'Program for first link in the chain.');



  31.   DBMS_SCHEDULER.create_program (

  32.     program_name   => 'test_program_2',

  33.     program_type   => 'PLSQL_BLOCK',

  34.     program_action => 'BEGIN

  35.                          INSERT INTO scheduler_test (id, description, created_date)

  36.                          VALUES (scheduler_test_seq.NEXTVAL, ''test_program_2'', SYSDATE);

  37.                          COMMIT;

  38.                        END;',

  39.     enabled        => TRUE,

  40.     comments       => 'Program for second link in the chain.');



  41.   DBMS_SCHEDULER.create_program (

  42.     program_name   => 'test_program_3',

  43.     program_type   => 'PLSQL_BLOCK',

  44.     program_action => 'BEGIN

  45.                          INSERT INTO scheduler_test (id, description, created_date)

  46.                          VALUES (scheduler_test_seq.NEXTVAL, ''test_program_3'', SYSDATE);

  47.                          COMMIT;

  48.                        END;',

  49.     enabled        => TRUE,

  50.     comments       => 'Program for last link in the chain.');

  51. END;

  52. BEGIN

  53.   DBMS_SCHEDULER.create_chain (

  54.     chain_name          => 'test_chain_1',

  55.     rule_set_name       => NULL,

  56.     evaluation_interval => NULL,

  57.     comments            => 'A test chain.');

  58. END;


  59. SELECT

  60.        chain_name,

  61.        rule_set_owner,

  62.        rule_set_name,

  63.        number_of_rules,

  64.        number_of_steps,

  65.        enabled,

  66.        comments

  67. FROM   user_scheduler_chains;


  68. BEGIN
  69.   
  70.   DBMS_SCHEDULER.define_chain_event_step (

  71.     chain_name   => 'test_chain_1',

  72.     step_name    => 'chain_step_1',

  73.     event_schedule_name => 'HR.SCHEDULE2');
  74.     end;

  75. begin
  76. DBMS_SCHEDULER.define_chain_step (

  77.     chain_name   => 'test_chain_1',

  78.     step_name    => 'chain_step_2',

  79.     program_name => 'test_program_1');



  80.   DBMS_SCHEDULER.define_chain_step (

  81.     chain_name   => 'test_chain_1',

  82.     step_name    => 'chain_step_3',

  83.     program_name => 'test_program_2');



  84.   DBMS_SCHEDULER.define_chain_step (

  85.     chain_name   => 'test_chain_1',

  86.     step_name    => 'chain_step_4',

  87.     program_name => 'test_program_3');

  88. END;


  89. ----------------------------------------------------------------


  90. BEGIN
  91.   
  92.   DBMS_SCHEDULER.define_chain_rule (
  93.   

  94.     chain_name => 'test_chain_1',

  95.     condition  => '1=1',

  96.     action     => 'START chain_step_1',

  97.     rule_name  => 'chain_rule_1',

  98.     comments   => 'First link in the chain.');







  99.   DBMS_SCHEDULER.define_chain_rule (
  100.   

  101.     chain_name => 'test_chain_1',

  102.     condition  => 'chain_step_1 completed',

  103.     action     => 'START chain_step_2',

  104.     rule_name  => 'chain_rule_2',

  105.     comments   => 'Second  link in the chain.');



  106.   DBMS_SCHEDULER.define_chain_rule (

  107.     chain_name => 'test_chain_1',

  108.     condition  => 'chain_step_2 completed',

  109.     action     => 'START chain_step_3',

  110.     rule_name  => 'chain_rule_3',

  111.     comments   => 'Third  link in the chain.');



  112.   DBMS_SCHEDULER.define_chain_rule (

  113.     chain_name => 'test_chain_1',

  114.     condition  => 'chain_step_3 completed',

  115.     action     => 'START chain_step_4',

  116.     rule_name  => 'chain_rule_4',

  117.     comments   => 'Fourth link in the chain.');



  118.   DBMS_SCHEDULER.define_chain_rule (

  119.     chain_name => 'test_chain_1',

  120.     condition  => 'chain_step_4 completed',

  121.     action     => 'END',

  122.     rule_name  => 'chain_rule_5',

  123.     comments   => 'End of the chain.');

  124. END;

  125. ----


  126. BEGIN
  127.   DBMS_SCHEDULER.ENABLE ('test_chain_1');
  128. END;


  129. SELECT *

  130. FROM   user_scheduler_running_chains;



  131. select  * from  scheduler_test;


  132. DECLARE

  133.   l_enqueue_options     DBMS_AQ.enqueue_options_t;

  134.   l_message_properties  DBMS_AQ.message_properties_t;

  135.   l_message_handle      RAW(16);

  136.   l_queue_msg           t_event_queue_payload;

  137. BEGIN

  138.   l_queue_msg := t_event_queue_payload('give_me_a_prod');



  139.   DBMS_AQ.enqueue(queue_name          => 'event_queue',

  140.                   enqueue_options     => l_enqueue_options,

  141.                   message_properties  => l_message_properties,

  142.                   payload             => l_queue_msg,

  143.                   msgid               => l_message_handle);

  144.   COMMIT;

  145. END;


  146. select  * from  hr.scheduler_test;

  147. SELECT *

  148. FROM   dba_scheduler_running_chains;
复制代码

2014-11-18-COMPSCHEDULER.sql:
  1. declare
  2.    v_1  timestamp;
  3. begin
  4.   for i in 1..10
  5.    loop
  6.     DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING (
  7.     calendar_string=>'hr.schedule4'   ,
  8.    start_date => sysdate,
  9.    return_date_after  => v_1,
  10.    next_run_date    => v_1 );
  11.   dbms_output.put_line(to_char(v_1,'YYYY-MM-DD:HH24:MI:SS'));
  12. end loop;
  13. end;

  14. 'FREQ=YEARLY;BYDATE=20180101;BYHOUR=14;BYMINUTE=10;BYSECOND=0;intersect=hr.schedule3'


  15. declare
  16.    v_1  timestamp;
  17. begin
  18.   for i in 1..10
  19.    loop
  20.     DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING (
  21.     calendar_string=> 'FREQ=YEARLY;BYDATE=0201;BYHOUR=14;BYMINUTE=10;BYSECOND=0;include=hr.schedule3'  ,
  22.    start_date => sysdate,
  23.    return_date_after  => v_1,
  24.    next_run_date    => v_1 );
  25.   dbms_output.put_line(to_char(v_1,'YYYY-MM-DD:HH24:MI:SS'));
  26. end loop;
  27. end;


  28. declare
  29.    v_1  timestamp;
  30. begin
  31.   for i in 1..10
  32.    loop
  33.     DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING (
  34.     calendar_string=> 'hr.scheduler5'  ,
  35.    start_date => sysdate,
  36.    return_date_after  => v_1,
  37.    next_run_date    => v_1 );
  38.   dbms_output.put_line(to_char(v_1,'YYYY-MM-DD:HH24:MI:SS'));
  39. end loop;
  40. end;
复制代码

2014-11-18-EMAIL.sql

  1. select  * from dba_scheduler_notifications;


  2. begin
  3.    dbms_scheduler.set_scheduler_attribute('email_server','station90.example.com:25');
  4.    end;
  5.    
  6.    
  7. begin
  8.    dbms_scheduler.set_scheduler_attribute('email_sender','oracle@example.com');
  9.    end;
  10.    
  11.    
  12.    
  13.    grant execute on utl_smtp  to hr;
  14.   BEGIN
  15. DBMS_SCHEDULER.add_job_email_notification (
  16.   job_name   =>  'hr.job9',
  17.   recipients =>  'oracle@example.com',
  18.   events     =>  'job_started, job_succeeded');
  19. END;
  20.    

  21. select  * from dba_scheduler_notifications;
  22.    
  23.   BEGIN
  24. DBMS_SCHEDULER.add_job_email_notification (
  25.   job_name   =>  'hr.job10',
  26.   recipients =>  'oracle@example.com',
  27.   events     =>  'job_failed');
  28. END;
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-12-5 03:19 , Processed in 0.050351 second(s), 24 queries .

快速回复 返回顶部 返回列表