Bo's Oracle Station

查看: 1798|回复: 0

job3/job4

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2017-10-14 17:15:07 | 显示全部楼层 |阅读模式
job复杂时间类型:
  1. BEGIN
  2. DBMS_SCHEDULER.CREATE_SCHEDULE
  3. (schedule_name => 'HR.SCHEDULE3'
  4. ,repeat_interval =>'freq=YEARLY;bydate=20171021,20171117,20171231'
  5. ,comments => 'schedule3'
  6. );
  7. END;
  8. ----

  9. BEGIN
  10. DBMS_SCHEDULER.CREATE_SCHEDULE
  11. (schedule_name => 'HR.SCHEDULE31'
  12. ,repeat_interval =>'freq=YEARLY;byday=MON,TUE,WED,THU,FRI;'
  13. ,comments => 'SCHEDULE31'
  14. );
  15. END;
  16. ---
  17. declare
  18.    v_1  timestamp;
  19. begin
  20.   for i in 1..10
  21.    loop
  22.     DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING (
  23.            calendar_string=>'freq=YEARLY;bydate=1021,1117,1231;BYHOUR=14;BYMINUTE=10;BYSECOND=0;exclude=HR.SCHEDULE31'   ,
  24.    start_date => sysdate,
  25.    return_date_after  => v_1,
  26.    next_run_date    => v_1 );
  27.   dbms_output.put_line(to_char(v_1,'YYYY-MM-DD:HH24:MI:SS'));
  28. end loop;
  29. end;
  30. ----
  31. BEGIN
  32. DBMS_SCHEDULER.CREATE_SCHEDULE
  33. (schedule_name => 'HR.SCHEDULE32'
  34. ,repeat_interval =>'freq=YEARLY;bydate=1021,1117,1231;BYHOUR=14;BYMINUTE=10;BYSECOND=0;exclude=HR.SCHEDULE31'
  35. ,comments => 'schedule32'
  36. );
  37. END;
  38. ---
  39. declare
  40.    v_1  timestamp;
  41. begin
  42.   for i in 1..10
  43.    loop
  44.     DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING (
  45.            calendar_string=>'HR.SCHEDULE32'   ,
  46.    start_date => sysdate,
  47.    return_date_after  => v_1,
  48.    next_run_date    => v_1 );
  49.   dbms_output.put_line(to_char(v_1,'YYYY-MM-DD:HH24:MI:SS'));
  50. end loop;
  51. end;
复制代码

sys的窗口 job4:

  1. select  * from dba_queues   q  where  q.QUEUE_TYPE='NORMAL_QUEUE' ;
  2. select  * from dba_queues q where q.QUEUE_TYPE='EXCEPTION_QUEUE';
  3. select  * from dba_queues q where q.QUEUE_TYPE   not in ('NORMAL_QUEUE','EXCEPTION_QUEUE');
  4. ----
  5. CREATE OR REPLACE TYPE t_event_queue_payload AS OBJECT (
  6.   event_name  VARCHAR2(30)
  7. );
  8. ---

  9. BEGIN
  10.   -- Create a queue table to hold the event queue.
  11.   DBMS_AQADM.create_queue_table(
  12.     queue_table        => 'event_queue_tab',
  13.     queue_payload_type => 't_event_queue_payload',
  14.     multiple_consumers => TRUE,
  15.     comment            => 'Queue Table For Event Messages');
  16.   -- Create the event queue.
  17.   DBMS_AQADM.create_queue (
  18.     queue_name  => 'event_queue',
  19.     queue_table => 'event_queue_tab');
  20.   -- Start the event queue.
  21.   DBMS_AQADM.start_queue (queue_name => 'event_queue');
  22. END;
  23. ----
  24. select  * from dba_queues   q  where  q.QUEUE_TYPE='NORMAL_QUEUE' ;
  25. select  * from dba_queues q where q.QUEUE_TYPE='EXCEPTION_QUEUE';
  26. select  * from dba_queues q where q.QUEUE_TYPE   not in ('NORMAL_QUEUE','EXCEPTION_QUEUE');
  27. ----
  28. select  * from dba_tab_privs p  where p.grantee='HR';
  29. ----
  30. begin
  31.    dbms_aqadm.grant_queue_privilege(privilege => 'ENQUEUE',queue_name => 'event_queue',grantee => 'HR');
  32. end;
  33.    
  34. begin
  35.    dbms_aqadm.grant_queue_privilege(privilege => 'DEQUEUE',queue_name => 'event_queue',grantee => 'HR');
  36. end;
  37. -------------------
  38. select  * from dba_tab_privs p  where p.grantee='HR';

  39. ------
  40. grant execute on dbms_aq to hr;
  41. ----
  42. select  * from dba_tab_privs p  where p.grantee='HR';

  43. -----
复制代码

hr的窗口job4:

  1. DROP TABLE scheduler_test;

  2. DROP SEQUENCE scheduler_test_seq;
  3. CREATE TABLE scheduler_test (
  4.   id            NUMBER(10)    NOT NULL,
  5.   created_date  DATE          NOT NULL,
  6.   CONSTRAINT scheduler_test_pk PRIMARY KEY (id)
  7. );

  8. select  * from scheduler_test;
  9. CREATE SEQUENCE scheduler_test_seq;
复制代码
Screenshot.png


Screenshot-1.png

Screenshot-2.png

grant execute on sys.t_event_queue_payload to hr;

SELECT * FROM scheduler_test order by id;

---
DECLARE
  l_enqueue_options     DBMS_AQ.enqueue_options_t;
  l_message_properties  DBMS_AQ.message_properties_t;
  l_message_handle      RAW(16);
  l_queue_msg           sys.t_event_queue_payload;
BEGIN
  l_queue_msg := sys.t_event_queue_payload('give_me_a_prod');

  DBMS_AQ.enqueue(queue_name          => 'sys.event_queue',
                  enqueue_options     => l_enqueue_options,
                  message_properties  => l_message_properties,
                  payload             => l_queue_msg,
                  msgid               => l_message_handle);
  COMMIT;
END;

----
SELECT * FROM scheduler_test order by id;
回复

使用道具 举报

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

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-25 05:09 , Processed in 0.059734 second(s), 27 queries .

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