Skip to content

Instantly share code, notes, and snippets.

@wave2
Created October 26, 2012 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wave2/3958276 to your computer and use it in GitHub Desktop.
Save wave2/3958276 to your computer and use it in GitHub Desktop.
Extracting content from JMS messages stored within OpenMQ HA DB
--
-- Here is a dissected view of one method to get at the JMS payload stored within a Blob column.
--
-- 1. First look within the Blob to find the word MyIdentifier and obtain the start position:
--
-- DBMS_LOB.INSTR(MESSAGE, UTL_RAW.CAST_TO_RAW('MyIdentifier'), 1, 1)
--
-- 2. Next pass the position from INSTR to the SUBSTR function and return 120 characters from the word 'MyIdentifier'
-- (needs to be less than the RAW limit of 2000 but enough to contain the info you want)
--
-- DBMS_LOB.SUBSTR(MESSAGE, 120, DBMS_LOB.INSTR(MESSAGE, UTL_RAW.CAST_TO_RAW('MyIdentifier'), 1, 1))
--
-- 3. We can now convert the resulting 120 character string (which should contain the information we are looking for) into a VARCHAR2.
--
-- UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(MESSAGE, 120, DBMS_LOB.INSTR(MESSAGE, UTL_RAW.CAST_TO_RAW('MyIdentifier'), 1, 1)))
--
-- 4. Finally we can use the REGEXP function (or anything else you fancy) to get at the important information e.g MyIdentifier
--
-- REGEXP_SUBSTR(UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(MESSAGE, 120, DBMS_LOB.INSTR(MESSAGE, UTL_RAW.CAST_TO_RAW('MyIdentifier'), 1, 1))), '[[:digit:]]+')
--
SELECT REGEXP_SUBSTR(UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(MESSAGE, 120, DBMS_LOB.INSTR(MESSAGE, UTL_RAW.CAST_TO_RAW('ApplicationId'), 1, 1))),'[[:digit:]]+') AS MyIdentifier FROM MQMSG41CMYJMSDB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment