Bo's Oracle Station

查看: 1349|回复: 0

课程第7次

[复制链接]

27

主题

27

帖子

183

积分

超级版主

Rank: 8Rank: 8

积分
183
发表于 2019-9-26 21:05:37 | 显示全部楼层 |阅读模式
Notice: This blog is written by Bo Tang.

------job5


  1. select  * from dba_scheduler_global_attribute;

  2. select  * from dba_scheduler_notifications;

  3. begin
  4. DBMS_SCHEDULER.SET_SCHEDULER_ATTRIBUTE
  5. ('email_server','192.168.0.79');
  6. end;

  7. begin
  8.   DBMS_SCHEDULER.SET_SCHEDULER_ATTRIBUTE
  9.   ('email_sender','oracle@example.com');
  10. end;


  11. begin
  12.   DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
  13.   job_name       =>'HR.JOB5',
  14.     events   =>'job_succeeded,job_completed',
  15.   recipients     =>'oracle@example.com');
  16. end;



  17. create or replace procedure hr.proc1
  18. begin
  19.   update t123456 set a=2;
  20. end;



  21. BEGIN
  22. DBMS_SCHEDULER.add_job_email_notification (
  23.   job_name         =>  'hr.job51',
  24.   recipients       =>  'oracle@example.com',
  25.   events           =>  'job_failed')
  26. ;
  27. END;



  28. -
复制代码

Bug 16623661

---job6

  1. select  * from hr.scheduler_test;

  2. DROP TABLE hr.scheduler_test;

  3. DROP SEQUENCE hr.scheduler_test_seq;


  4. CREATE TABLE hr.scheduler_test (
  5.   id            NUMBER(10)    NOT NULL,
  6.   description   VARCHAR2(20)  NOT NULL,
  7.   created_date  DATE          NOT NULL,
  8.   CONSTRAINT scheduler_test_pk PRIMARY KEY (id)
  9. );

  10. CREATE SEQUENCE hr.scheduler_test_seq;

  11. select  * from hr.scheduler_test;


  12. DECLARE
  13.   l_enqueue_options     DBMS_AQ.enqueue_options_t;
  14.   l_message_properties  DBMS_AQ.message_properties_t;
  15.   l_message_handle      RAW(16);
  16.   l_queue_msg           sys.t_event_queue_payload;
  17. BEGIN
  18.   l_queue_msg := sys.t_event_queue_payload('Chemical_Wrong');

  19.   DBMS_AQ.enqueue(queue_name          => 'sys.event_queue',
  20.                   enqueue_options     => l_enqueue_options,
  21.                   message_properties  => l_message_properties,
  22.                   payload             => l_queue_msg,
  23.                   msgid               => l_message_handle);
  24.   COMMIT;
  25. END;
复制代码
-----------------------------------

如果HR本人,需要以下权限
BEGIN
DBMS_RULE_ADM.grant_system_privilege(
    privilege    =>DBMS_RULE_ADM.create_rule_set_obj,
    grantee      => 'HR',
    grant_option => FALSE);
DBMS_RULE_ADM.grant_system_privilege(
    privilege    =>DBMS_RULE_ADM.create_evaluation_context_obj,
    grantee      => 'HR',
    grant_option => FALSE);
DBMS_RULE_ADM.grant_system_privilege(
     privilege   => DBMS_RULE_ADM.create_rule_obj,
    grantee      => 'HR',
    grant_option => FALSE);
END;
--------------------------------------------------
规则编程的条件语法示例:
  1. ':step1.state=''SUCCEEDED'' and :step2.error_code=3'

  2. '1=1'

  3. ':step3.state != ''COMPLETED'''

  4. ':step2.error_code not in (1,2,3)'

  5. ':step1.state = ''NOT_STARTED'''
复制代码

--------------------

  1. BEGIN
  2.   DBMS_SCHEDULER.create_program (
  3.     program_name   => 'hr.test_program_1',
  4.     program_type   => 'PLSQL_BLOCK',
  5.     program_action => 'BEGIN
  6.                          INSERT INTO hr.scheduler_test (id, description, created_date)
  7.                          VALUES (hr.scheduler_test_seq.NEXTVAL, ''test_program_1'', SYSDATE);
  8.                          COMMIT;
  9.                        END;',
  10.     enabled        => TRUE,
  11.     comments       => 'Step2');

  12.   DBMS_SCHEDULER.create_program (
  13.     program_name   => 'hr.test_program_2',
  14.     program_type   => 'PLSQL_BLOCK',
  15.     program_action => 'BEGIN
  16.                          INSERT INTO hr.scheduler_test (id, description, created_date)
  17.                          VALUES (hr.scheduler_test_seq.NEXTVAL, ''test_program_2'', SYSDATE);
  18.                          COMMIT;
  19.                        END;',
  20.     enabled        => TRUE,
  21.     comments       => 'Step3');

  22.   DBMS_SCHEDULER.create_program (
  23.     program_name   => 'hr.test_program_3',
  24.     program_type   => 'PLSQL_BLOCK',
  25.     program_action => 'BEGIN
  26.                          INSERT INTO hr.scheduler_test (id, description, created_date)
  27.                          VALUES (hr.scheduler_test_seq.NEXTVAL, ''test_program_3'', SYSDATE);
  28.                          COMMIT;
  29.                        END;',
  30.     enabled        => TRUE,
  31.     comments       => 'Step4');
  32. END;
复制代码
1.png
test_chain:
  1. BEGIN
  2.   DBMS_SCHEDULER.run_chain (
  3.     chain_name    =>  'test_chain_1',
  4.     job_name      =>  'test_chain_1_run_job',
  5.     start_steps   =>  'chain_step_1, chain_step_2, chain_step_3');
  6. END;
复制代码

2.png





回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-5-20 03:16 , Processed in 0.032825 second(s), 27 queries .

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