服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Oracle - Oracle高级队列(Advanced Queue)简单实例

Oracle高级队列(Advanced Queue)简单实例

2020-01-10 18:08lqh Oracle

这篇文章主要介绍了Oracle高级队列(Advanced Queue)简单实例的相关资料,需要的朋友可以参考下

Oracle高级队列(Advanced Queue)简单实例

最简单的高级队列的练习,基本上都使用了默认参数。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- Create Type
create or replace type note as Object(
 subject varchar2(100),
 Content varchar2(2000),CreateTime date
);
 
-- Create queue table
begin
 sys.dbms_aqadm.create_queue_table(
  queue_table => 'NOTETAB',
  queue_payload_type => 'TEST.NOTE'
end;
 
--create queue
begin
 sys.dbms_aqadm.create_queue(
  queue_name => 'NOTEQ',
  queue_table => 'NOTETAB',
  queue_type => sys.dbms_aqadm.normal_queue,
  max_retries => 5,
  retry_delay => 0,
  retention_time => 0);
end;
 
--enqueue
declare
v_Message note;
v_MsgId RAW(16);
v_options DBMS_AQ.ENQUEUE_OPTIONS_T;
v_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
v_Recipients DBMS_AQ.AQ$_RECIPIENT_LIST_T;
begin
   v_Message:=note(subject => 'note3',Content => 'content3',createTime => sysdate);
 
--   v_Recipients(0) := sys.aq$_agent('NOTE','MTQ',0);
--   v_properties.recipient_list := v_Recipients;
   v_options.visibility :=DBMS_AQ.IMMEDIATE;
   dbms_aq.enqueue(queue_name => 'noteq',enqueue_options => v_options,message_properties => v_properties,payload => v_Message,msgid => v_MsgId);
   dbms_output.put_line('encode success,msgid is '||v_MsgId);
 
end;
 
--dequeue
declare
v_Message note;
v_MsgId RAW(16);
v_options DBMS_AQ.DEQUEUE_OPTIONS_T;
v_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
v_Recipients DBMS_AQ.AQ$_RECIPIENT_LIST_T;
begin
 
--   v_Recipients(0) := sys.aq$_agent('NOTE','MTQ',0);
--   v_properties.recipient_list := v_Recipients;
   v_options.visibility :=DBMS_AQ.IMMEDIATE;
   dbms_aq.dequeue(queue_name => 'noteq',dequeue_options => v_options,message_properties => v_properties,payload => v_Message,msgid => v_MsgId);
   dbms_output.put_line('decode success,msgid is '||v_MsgId);
   dbms_output.put_line('subject is '||v_Message.subject);
   dbms_output.put_line('Content is '||v_Message.Content);
   dbms_output.put_line('createTime is '||to_char(v_Message.createTime,'yyyy-mm-dd hh24:mi:ss'));
end;

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

原文链接:http://blog.csdn.net/54powerman/article/details/821996

延伸 · 阅读

精彩推荐