Bo's Oracle Station

查看: 2241|回复: 0

第61-62次:2015-06-06星期六

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2015-5-29 09:57:14 | 显示全部楼层 |阅读模式
eventbase11g.sql
  1. select  * from scheduler_test;

  2. truncate table scheduler_test;

  3. select scheduler_test_seq.currval from dual;


  4. DECLARE

  5.   l_enqueue_options     DBMS_AQ.enqueue_options_t;

  6.   l_message_properties  DBMS_AQ.message_properties_t;

  7.   l_message_handle      RAW(16);

  8.   l_queue_msg           t_event_queue_payload;

  9. BEGIN

  10.   l_queue_msg := t_event_queue_payload('give_me_a_pear');



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

  12.                   enqueue_options     => l_enqueue_options,

  13.                   message_properties  => l_message_properties,

  14.                   payload             => l_queue_msg,

  15.                   msgid               => l_message_handle);

  16.   COMMIT;

  17. END;

  18. select  * from scheduler_test;


  19. -----
  20. ------
  21. create or replace procedure proc_test( p_1  number , p_2  out   number)
  22. is
  23. begin
  24.   update employees set salary=10000 where employee_id=p_1;
  25.   select  salary into p_2 from  employees  where employee_id=p_1;
  26. end;

  27. select  * from user_errors;


  28. declare
  29.   v_salary  number(8,2);
  30. begin
  31.   proc_test(100,v_salary);
  32.   dbms_output.put_line(v_salary);
  33. end;
  34. ----
  35. ----
  36. create or replace procedure  proc_test_io( p_1  in out number )  
  37. is
  38. begin
  39.   p_1 := p_1*2;
  40.   
  41. end;

  42. select  * from user_errors;

  43. ------






  44. ---
  45. declare
  46.   v_1 number;
  47. begin
  48.    v_1 := 1;
  49.    proc_test_io( v_1);
  50.    dbms_output.put_line(v_1);
  51. end;

  52. -----

  53. -----------------------------------------------------------



  54. create or replace procedure  procnew( p_1     t_event_queue_payload    )
  55. is

  56. BEGIN
  57.      INSERT INTO scheduler_test (id, created_date)
  58.          VALUES (scheduler_test_seq.NEXTVAL, SYSDATE);
  59.          COMMIT;
  60. END;

  61. select  * from user_errors;

  62. begin
  63.   dbms_scheduler.create_program (
  64.    program_name => 'programnew',
  65.     program_action=> 'procnew',
  66.     program_type => 'STORED_PROCEDURE',
  67.     number_of_arguments => 1,
  68.     enabled => false) ;
  69. end;


  70. select  * from user_scheduler_programs;

  71. select  * from user_scheduler_program_args;

  72. begin
  73.    dbms_scheduler.define_metadata_argument (
  74.     program_name => 'programnew',
  75.     argument_position => 1 ,
  76.    metadata_attribute => 'EVENT_MESSAGE') ;
  77.    
  78. end;


  79. select  * from user_scheduler_program_args;

  80. begin
  81. dbms_scheduler.enable ('programnew');
  82. end;
  83. ---------------------------------

  84. alter table    scheduler_test add ( event_name  varchar2(40)) ;

  85. select  * from scheduler_test;

  86. create or replace procedure  procnew( p_1     t_event_queue_payload    )
  87. is

  88. BEGIN
  89.      INSERT INTO scheduler_test
  90.          VALUES (scheduler_test_seq.NEXTVAL, SYSDATE,     p_1.event_name   );
  91.          COMMIT;
  92. END;

  93. select  * from user_errors;

  94. begin
  95.   dbms_scheduler.create_program (
  96.    program_name => 'programnew2',
  97.     program_action=> 'procnew',
  98.     program_type => 'STORED_PROCEDURE',
  99.     number_of_arguments => 1,
  100.     enabled => false) ;
  101. end;

  102. begin
  103.    dbms_scheduler.define_metadata_argument (
  104.     program_name => 'programnew2',
  105.     argument_position => 1 ,
  106.    metadata_attribute => 'EVENT_MESSAGE') ;
  107.    
  108. end;

  109. begin
  110. dbms_scheduler.enable ('programnew2');
  111. end;
  112. select  * from user_scheduler_program_args;

  113. select  * from scheduler_test;
复制代码

chain11g.sql:

  1. BEGIN
  2.   
  3.   DBMS_SCHEDULER.define_chain_rule (
  4.   

  5.     chain_name => 'test_chain_1',

  6.     condition  => '1=1',

  7.     action     => 'START chain_step_1',

  8.     rule_name  => 'chain_rule_1',

  9.     comments   => 'First link in the chain.');
  10.    
  11.     end;


  12. ---
  13. begin
  14.   DBMS_SCHEDULER.define_chain_rule (
  15.   

  16.     chain_name => 'test_chain_1',

  17.     condition  => 'chain_step_1 completed',

  18.     action     => 'START chain_step_2',

  19.     rule_name  => 'chain_rule_2',

  20.     comments   => 'Second  link in the chain.');
  21.   end;

  22. begin
  23.   DBMS_SCHEDULER.define_chain_rule (
  24.   

  25.     chain_name => 'test_chain_1',

  26.     condition  => 'chain_step_2    completed',

  27.     action     => 'START chain_step_3',

  28.     rule_name  => 'chain_rule_3',

  29.     comments   => '3rd link in the chain.');
  30.   end;



  31. begin
  32.   DBMS_SCHEDULER.define_chain_rule (
  33.   

  34.     chain_name => 'test_chain_1',

  35.     condition  => 'chain_step_3    completed',

  36.     action     => 'START chain_step_4',

  37.     rule_name  => 'chain_rule_4',

  38.     comments   => '4th link in the chain.');
  39.   end;
  40.   
  41.   begin
  42.   DBMS_SCHEDULER.define_chain_rule (

  43.     chain_name => 'test_chain_1',

  44.     condition  => 'chain_step_4 completed',

  45.     action     => 'END',

  46.     rule_name  => 'chain_rule_5',

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

  48. END;



  49. BEGIN
  50.   DBMS_SCHEDULER.ENABLE ('test_chain_1');
  51. END;

  52. select  * from user_scheduler_chains;


  53. SELECT *

  54. FROM   user_scheduler_running_chains;

  55. select  * from scheduler_test;


  56. DECLARE

  57.   l_enqueue_options     DBMS_AQ.enqueue_options_t;

  58.   l_message_properties  DBMS_AQ.message_properties_t;

  59.   l_message_handle      RAW(16);

  60.   l_queue_msg           t_event_queue_payload;

  61. BEGIN

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



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

  64.                   enqueue_options     => l_enqueue_options,

  65.                   message_properties  => l_message_properties,

  66.                   payload             => l_queue_msg,

  67.                   msgid               => l_message_handle);

  68.   COMMIT;

  69. END;
  70. ---
  71. truncate table scheduler_test;

  72. select  * from scheduler_test;
复制代码

database-remote.sql:
  1. alter system set dispatchers='(PROTOCOL=TCP) (dispatchers=6)';



  2. select  * from dba_users  order by 1;

  3. BEGIN
  4. DBMS_XDB.SETHTTPPORT(8888);
  5. END;

  6. SQL> @?/rdbms/admin/prvtrsch.plb




  7. BEGIN
  8. DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('mypassword');
  9. END;

  10. SELECT DBMS_XDB.GETHTTPPORT() FROM DUAL;


  11. DECLARE
  12. versionnum VARCHAR2(30);
  13. BEGIN
  14. versionnum := DBMS_SCHEDULER.GET_AGENT_VERSION('192.168.0.199');
  15. DBMS_OUTPUT.PUT_LINE(versionnum);
  16. END;



  17. select  * from dba_scheduler_db_dests;

  18. select  * from dba_scheduler_external_dests;




  19. select  * from dba_scheduler_external_dests;
  20. select * from dba_scheduler_dests;
  21. select  * from dba_scheduler_db_dests;


  22. begin
  23.    dbms_scheduler.create_database_destination(destination_name => 'DB_2',agent => 'agent_1',
  24.    tns_name => '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.199)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = utforcl.example.com)))');
  25.    end;
  26.    
  27. begin
  28.    dbms_scheduler.create_database_destination(destination_name => 'DB_1',agent => 'agent_1',
  29.    tns_name => '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.199)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.example.com)))');
  30.    end;
  31.    
  32.    
  33. select  * from dba_scheduler_credentials;  
  34.    
  35.    BEGIN
  36. sys.dbms_scheduler.create_job(
  37. job_name => '"HR"."JOB_REMOTE_DB_ORCL"',
  38. job_type => 'PLSQL_BLOCK',
  39. job_action => 'begin
  40.    update employees set salary=salary+1  where employee_id=100;
  41.    commit;
  42. end;',
  43. start_date => systimestamp at time zone 'Asia/Shanghai',
  44. job_class => '"DEFAULT_JOB_CLASS"',
  45. comments => 'JOB_REMOTE_DB2',
  46. auto_drop => FALSE,
  47. credential_name =>'"SYS"."CREDENTIAL2"' ,destination_name =>'SYS.DB_1' ,
  48. enabled => true);
  49. END;

  50.    BEGIN
  51. sys.dbms_scheduler.create_job(
  52. job_name => '"HR"."JOB_REMOTE_DB_UTFORCL"',
  53. job_type => 'STORED_PROCEDURE',
  54. job_action => 'HR.PROC1',
  55. start_date => systimestamp at time zone 'Asia/Shanghai',
  56. job_class => '"DEFAULT_JOB_CLASS"',
  57. comments => 'JOB_REMOTE_DB2',
  58. auto_drop => FALSE,
  59. credential_name =>'"SYS"."CREDENTIAL2"' ,destination_name =>'SYS.DB_2' ,
  60. enabled => true);
  61. END;


  62. select  * from dba_scheduler_groups;
  63. select  * from dba_scheduler_group_members;

  64. BEGIN
  65.   DBMS_SCHEDULER.create_group(
  66.     group_name    => 'hr.group1',
  67.     group_type    => 'DB_DEST',member => 'LOCAL,DB_1,DB_2'
  68.     );
  69. END;


  70. select  * from dba_scheduler_groups  g where g.group_name='GROUP1';
  71. select  * from dba_scheduler_group_members  gm where gm.group_name='GROUP1';


  72. BEGIN
  73. sys.dbms_scheduler.create_job(
  74. job_name => '"HR"."JOB_REMOTE_DB_GROUP"',
  75. job_type => 'PLSQL_BLOCK',
  76. job_action => 'begin
  77.    update employees set salary=9999  where employee_id=100;
  78.    commit;
  79. end;',
  80. start_date => systimestamp at time zone 'Asia/Shanghai',
  81. job_class => '"DEFAULT_JOB_CLASS"',
  82. comments => 'JOB_REMOTE_GROUP',
  83. auto_drop => FALSE,
  84. credential_name =>'"SYS"."CREDENTIAL2"' ,destination_name =>'HR.GROUP1' ,
  85. enabled => true);
  86. END;

  87. select  *  from  dba_SCHEDULER_JOB_RUN_DETAILS;






复制代码

jobarry.sql:

  1. create table t05317_lw( a  number ) ;
  2. alter table t05317_lw  modify ( a date ) ;


  3. create or replace procedure  proc05317_lw
  4. is
  5. begin
  6.    insert into  t05317_lw values(sysdate);
  7.    commit;
  8. end;

  9. --EM---

  10. begin
  11.    dbms_scheduler.create_job(
  12.    job_name => 'lwjob',
  13.    program_name=>'proglw',
  14.    schedule_name=>'schedulelw',
  15.    job_style=>'LIGHTWEIGHT');
  16. end;

  17. ----


  18. DECLARE
  19.     newjob sys.job;
  20.      newjobarr sys.job_array;
  21. BEGIN
  22. -- Create an array of JOB object types
  23.      newjobarr := sys.job_array();
  24. -- Allocate sufficient space in the array
  25.       newjobarr.extend(100);
  26. -- Add definitions for jobs
  27.      FOR i IN 1..100 LOOP
  28.    -- Create a JOB object type
  29.      newjob := sys.job(job_name => 'LWTJK' || to_char(i),
  30.                      job_style => 'LIGHTWEIGHT',
  31.                      job_template => 'proglw',
  32.                          enabled => TRUE );
  33. -- Add job to the array
  34.          newjobarr(i) := newjob;
  35. END LOOP;
  36. -- Call CREATE_JOBS to create jobs in one transaction
  37. DBMS_SCHEDULER.CREATE_JOBS(newjobarr, 'TRANSACTIONAL');
  38. END;

  39. select  * from hr.t05317_lw;










复制代码

window_group.sql:
  1. create or replace procedure  hr.proc21
  2. is
  3. begin
  4.   update hr.employees set salary=salary+1 where employee_id=200;
  5.   commit;
  6. end;



  7. BEGIN
  8.   DBMS_SCHEDULER.create_group(
  9.     group_name    => 'hr.group1',
  10.     group_type    => 'DB_DEST',
  11.     member        => 'LOCAL');
  12. END;

  13. SELECT group_name, member_name
  14. FROM   user_scheduler_group_members;




  15. BEGIN
  16. DBMS_SCHEDULER.CREATE_JOB (
  17.    job_name            =>  'hr.job21',
  18.    job_type            =>  'stored_procedure',
  19.    job_action          =>  'hr.proc21',
  20.    start_date          =>  SYSTIMESTAMP,
  21.    repeat_interval     =>  'freq=minutely; bysecond=0',
  22.    end_date            =>  SYSTIMESTAMP + 1/24,
  23.    credential_name     =>  'credential14',
  24.    destination_name    =>  'hr.group1',
  25.    enabled             =>  TRUE);
  26. END;
复制代码



回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-25 12:09 , Processed in 0.032127 second(s), 24 queries .

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