/* 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;
/
阅读(9635) | 评论(0) | 转发(0) |