Oracle formatted hex dump of a string

Recently I ran into the problem that some regexp_substr was not giving the result that I expected. It turned out that when I tested my code, the line-ending looked like Windows CRLF, but internally it was only and LF. When I copied the test string data from SQL Developer into my script, it was converted automatically and without notice. Grgrgrgr! So I was wondering how to be able to inspect the data that was subject of the regexp_substr. Searches lead me to RAWTOHEX(UTL_RAW.CAST_TO_RAW(yourstringhere)). But I did not like the looooong output. So I wrote my own function :-).

I finally was satisfied with the HEX_DUMP function that gave me this output of the first 300 characters of Lipsum (with some new lines added).

0001: 4c 6f 72 65 6d 20 69 70 73 75 6d 20 64 6f 6c 6f = Lorem ipsum dolo
0017: 72 20 73 69 74 20 61 6d 65 74 2c 20 63 6f 6e 73 = r sit amet, cons
0033: 65 63 74 65 74 75 72 20 61 64 69 70 69 73 63 69 = ectetur adipisci
0049: 6e 67 20 0a 65 6c 69 74 2e 20 56 69 76 61 6d 75 = ng ·elit. Vivamu
0065: 73 20 6d 6f 6c 65 73 74 69 65 20 64 69 61 6d 20 = s molestie diam
0081: 69 64 20 63 6f 6e 73 65 71 75 61 74 20 76 65 68 = id consequat veh
0097: 69 63 75 6c 61 2e 0a 4d 61 65 63 65 6e 61 73 20 = icula.·Maecenas
0113: 76 65 6e 65 6e 61 74 69 73 20 73 65 6d 20 76 69 = venenatis sem vi
0129: 74 61 65 20 73 65 6d 20 6c 75 63 74 75 73 2c 20 = tae sem luctus,
0145: 61 20 63 6f 6d 6d 6f 64 6f 0a 61 75 67 75 65 20 = a commodo·augue
0161: 6c 75 63 74 75 73 2e 20 56 69 76 61 6d 75 73 20 = luctus. Vivamus
0177: 74 65 6d 70 6f 72 20 62 6c 61 6e 64 69 74 20 6c = tempor blandit l
0193: 6f 72 65 6d 2c 20 61 63 0a 70 75 6c 76 69 6e 61 = orem, ac·pulvina
0209: 72 20 6c 65 63 74 75 73 20 74 65 6d 70 6f 72 20 = r lectus tempor
0225: 71 75 69 73 2e 20 53 75 73 70 65 6e 64 69 73 73 = quis. Suspendiss
0241: 65 20 64 75 69 0a 73 61 70 69 65 6e 2c 20 74 69 = e dui·sapien, ti
0257: 6e 63 69 64 75 6e 74 20 65 75 20 72 69 73 75 73 = ncidunt eu risus
0273: 20 69 64 2c 20 70 65 6c 6c 65 6e 74 65 73 71 75 =  id, pellentesqu
0289: 65 20 63 6f 6e 67 75 65 0a 73 65 64 2e 20<      = e congue·sed.

 

You can download the source from my_utl_hex.

Comments are closed.

Herman Mol is powered by WordPress.  Staypressed theme by Themocracy