Bo's Oracle Station

查看: 2411|回复: 0

第60次:2015-06-04星期四

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2015-5-29 09:53:00 | 显示全部楼层 |阅读模式
  1. select  * from dba_scheduler_credentials;

  2. begin
  3.   dbms_scheduler.create_credential(
  4.         credential_name => 'credlocalfw',
  5.         username => 'oracle',
  6.         password => 'oracle');
  7. end;

  8. grant execute  on credlocalfw  to hr;

  9. begin
  10.    dbms_scheduler.create_file_watcher(
  11.        file_watcher_name => 'filewlocal',
  12.        directory_path => '/home/oracle/dirfw',
  13.        file_name => 'botang*.txt',
  14.        credential_name => 'credlocalfw');
  15. end;


  16. ----------------------------------

  17. select  * from dba_scheduler_file_watchers;

  18. grant execute on filewlocal to hr;


  19. grant execute on SYS.SCHEDULER_FILEWATCHER_RESULT   to hr;
  20. grant create external job to hr;
  21. grant create job to hr;

  22. create table hr.tfilewlocal    ( a  varchar2(200)  ) ;  

  23. create or replace procedure hr.procfilewlocal ( p_1   SYS.SCHEDULER_FILEWATCHER_RESULT)
  24. is
  25. begin
  26.   insert into     tfilewlocal   values ( to_char( p_1.file_timestamp,'YYYY-MM-DD:HH24:MI:SS') ||'      '
  27.                                                       ||p_1.directory_path||'        '
  28.                                                       ||p_1.actual_file_name||'       '
  29.                                                       ||p_1.file_size  ) ;
  30.   commit;
  31. end;


  32. begin
  33.     dbms_scheduler.create_program(
  34.      program_name => 'HR.progfilewlocal',
  35.      program_type => 'STORED_PROCEDURE',
  36.      program_action => 'HR.procfilewlocal',
  37.      number_of_arguments => 1,
  38.      enabled => false);
  39. end;

  40. begin
  41.    dbms_scheduler.define_metadata_argument(
  42.    program_name => 'HR.progfilewlocal',
  43.    metadata_attribute => 'event_message',argument_position => 1 ) ;
  44. end;

  45. begin
  46.   dbms_scheduler.enable('HR.progfilewlocal');
  47. end;

  48. begin
  49.    dbms_scheduler.set_attribute('hr.jobfilewlocal','parallel_instances',true);
  50. end;



  51. select  * from  hr.tfilewlocal ;


  52. -------remote
  53. begin
  54.   dbms_scheduler.create_credential(
  55.         credential_name => 'credremotefw',
  56.         username => 'botang',
  57.         password => 'oracle');
  58. end;

  59. grant execute  on credremotefw  to hr;

  60. select  * from dba_scheduler_external_dests;

  61. begin
  62.    dbms_scheduler.create_file_watcher(
  63.    file_watcher_name => 'filewremote',
  64.    directory_path => 'c:\app\Administrator\dirfw',
  65.    file_name =>  'botang*.txt',
  66.    credential_name => 'credremotefw',
  67.    destination => 'STATION199');
  68. end;
  69.    
  70.   select  * from dba_scheduler_file_watchers;
  71.    
  72.   grant execute on filewremote to hr;
  73.    
  74.    create table hr.tfilewremote   ( a  varchar2(200)  ) ;  

  75. create or replace procedure hr.procfilewremote ( p_1   SYS.SCHEDULER_FILEWATCHER_RESULT)
  76. is
  77. begin
  78.   insert into     tfilewremote   values ( to_char( p_1.file_timestamp,'YYYY-MM-DD:HH24:MI:SS') ||'      '
  79.                                                       ||p_1.directory_path||'        '
  80.                                                       ||p_1.actual_file_name||'       '
  81.                                                       ||p_1.file_size  ) ;
  82.   commit;
  83. end;
  84.   
  85. begin
  86.     dbms_scheduler.create_program(
  87.      program_name => 'HR.progfilewremote',
  88.      program_type => 'STORED_PROCEDURE',
  89.      program_action => 'HR.procfilewremote',
  90.      number_of_arguments => 1,
  91.      enabled => false);
  92. end;

  93. begin
  94.    dbms_scheduler.define_metadata_argument(
  95.    program_name => 'HR.progfilewremote',
  96.    metadata_attribute => 'event_message',argument_position => 1 ) ;
  97. end;

  98. begin
  99.   dbms_scheduler.enable('HR.progfilewremote');
  100. end;

  101. --EM---job
  102. BEGIN
  103.   DBMS_SCHEDULER.CREATE_JOB(
  104.    jOB_NAME=> 'hr.teacherjob1',
  105.     PROGRAM_NAME=> 'hr.teacherprog1',
  106.    EVENT_CONDITION => 'tab.user_data.file_size > 10',
  107.    QUEUE_SPEC=> 'teacherfilew1',
  108.    AUTO_DROP=> FALSE,
  109.   ENABLED=> true);
  110. END;



  111. begin
  112.    dbms_scheduler.set_attribute('hr.jobfilewremote','parallel_instances',true);
  113. end;

  114. select * from   hr.tfilewremote;
  115.       
  116. select  * from  hr.tfilewlocal;

  117.   select  * from dba_scheduler_file_watchers;
  118.   
  119. -------------------------------

  120. select  * from dba_scheduler_db_dests;

  121. begin
  122.    dbms_scheduler.create_database_destination(
  123.      destination_name => 'db199',
  124.      agent => 'station199',tns_name => 'orcl199');
  125.   end

  126. begin
  127.   dbms_scheduler.create_credential(
  128.         credential_name => 'credremotedb',
  129.         username => 'hr',
  130.         password => 'hr');
  131. end;


  132. grant execute on credremotedb to hr;

  133. BEGIN
  134. sys.dbms_scheduler.create_job(
  135. job_name => '"HR"."JOBREMOTEDB2"',
  136. job_type => 'STORED_PROCEDURE',
  137. job_action => '"HR"."PROC05317WIN"',
  138. start_date => systimestamp at time zone 'PRC',
  139. job_class => '"DEFAULT_JOB_CLASS"',
  140. comments => 'jobremotedb',
  141. auto_drop => FALSE,
  142. enabled => FALSE,credential_name => 'sys.credremotedb',destination_name => 'db199');
  143. end;


  144. begin
  145. sys.dbms_scheduler.enable( '"HR"."JOBREMOTEDB2"' );
  146. END;






  147. BEGIN
  148.   DBMS_SCHEDULER.CREATE_JOB(
  149.    jOB_NAME=> 'hr.teacherjob1',
  150.     PROGRAM_NAME=> 'hr.teacherprog1',
  151.    EVENT_CONDITION => 'tab.user_data.file_size > 10',
  152.    QUEUE_SPEC=> 'teacherfilew1',
  153.    AUTO_DROP=> FALSE,
  154.   ENABLED=> true);
  155. END;




  156. EGIN
  157. sys.dbms_scheduler.create_job(
  158. job_name => '"HR"."JOBFILEW1"',
  159. program_name => '"HR"."PROGFILEW1"',
  160. event_condition => 'tab.user_data.file_size > 10',
  161. queue_spec => '"SYS"."FILEW1"',
  162. start_date => systimestamp at time zone 'Asia/Shanghai',
  163. job_class => '"DEFAULT_JOB_CLASS"',
  164. comments => 'jobfilew1',
  165. auto_drop => FALSE,
  166. enabled => TRUE);
  167. END;




  168. begin
  169.    dbms_scheduler.set_attribute('hr.jobfilew1','parallel_instances',true);
  170. end;

  171. ---

  172. grant execute on SYS.SCHEDULER_FILEWATCHER_RESULT   to hr;
复制代码


回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-11-22 05:27 , Processed in 0.041209 second(s), 24 queries .

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