Chinaunix首页 | 论坛 | 博客
  • 博客访问: 94538
  • 博文数量: 25
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 316
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-02 00:39
文章分类

全部博文(25)

文章存档

2013年(25)

我的朋友

分类: Oracle

2013-04-22 16:06:05

/* Formatted on 1/15/2012 11:59:52 PM (QP5 v5.163.1008.3004) */
CREATE OR REPLACE PROCEDURE SYS.mq_to_oracle (local_queue IN VARCHAR2)
IS
   objdesc      PGM.MQOD;
   hobj         PGM.MQOH;
   msgdesc      PGM.MQMD;
   putmsgopts   PGM.MQPMO;
   getmsgopts   PGM.MQGMO;
   options      BINARY_INTEGER;
   getbuffer    RAW (32767);
BEGIN
   objdesc.objectname := local_queue;
   objdesc.dblinkname := 'dg4mqs';

   -- 指定get的option


   options := pgm_sup.MQOO_INPUT_AS_Q_DEF;


   -- 打开queue


   PGM.MQOPEN (objdesc, options, hobj);


   -- 初始化buffer

   PGM.MQRAW_INIT (getbuffer, 32767);


   -- 调用get方法取得message

   getmsgopts.msglength := 32767;
   PGM.MQGET (hobj,
              msgdesc,
              getmsgopts,
              getbuffer);


   -- 定义关闭队列的option


   options := pgm_sup.MQCO_NONE;


   -- 关闭队列


   PGM.MQCLOSE (hobj, options);


   DBMS_OUTPUT.put_line (
      'message read back = ' || UTL_RAW.cast_to_varchar2 (getbuffer));

   COMMIT;
EXCEPTION
   -- 如果没有消息就关闭连接

   WHEN pgm_sup.NO_MORE_MESSAGES
   THEN
      DBMS_OUTPUT.put_line ('Warning: No message found on the queue');
      options := pgm_sup.MQCO_NONE;
      PGM.MQCLOSE (hobj, options);
      ROLLBACK;
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error: Failed to get the message');
      DBMS_OUTPUT.put_line (SQLERRM);
      ROLLBACK;
END;
/
阅读(9598) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~