ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling
complimentary technical Workshops on Database Security for the first 30
Oracle Database customers located anywhere in North America, EMEA, LATAM, or
APAC that send an email to
asra_us@oracle.com. Request a Workshop for
your organization today.
Purpose
Utilities for working with the RAW data type
AUTHID
DEFINER
Constants
Name
Data Type
Value
big_endian
PLS_INTEGER
1
little_endian
PLS_INTEGER
2
machine_endian
PLS_INTEGER
3
Dependencies
SELECT name FROM dba_dependencies WHERE referenced_name = 'UTL_RAW'
UNION
SELECT referenced_name FROM dba_dependencies WHERE name = 'UTL_RAW';
-- returns 232 rows
Documented
Yes
Exceptions
Error Code
Reason
ORA-6502
VALUE_ERROR: An arithmetic, conversion, truncation, or size-constraint error. Usually raised by trying to cram a 6 character string into a VARCHAR2(5).
To extract a substring from a BLOB using a PL/SQL program use dbms_lob.substr().
The problem is that it returns a string in hexadecimal characters. CAST_TO_VARCHAR2 turns the hexadecimal string into readable ascii format.
utl_raw.cast_to_varchar2(r IN RAW) RETURN VARCHAR2;
set serveroutput on
BEGIN
FOR i IN 100..200 LOOP
dbms_output.put_line(utl_raw.cast_to_varchar2(TO_CHAR(i)));
END LOOP;
END;
/
Demo 2
SELECT rawtohex('!4!4!4!4!4!4') FROM dual;
SELECT utl_raw.cast_to_varchar2('213421342134213421342134') FROM dual;
Concatenate a set of 12 raws into a single raw (up to 32K)
utl_raw.concat(r1 IN RAW DEFAULT NULL,
r2 IN RAW DEFAULT NULL,
r3 IN RAW DEFAULT NULL,
r4 IN RAW DEFAULT NULL,
r5 IN RAW DEFAULT NULL,
r6 IN RAW DEFAULT NULL,
r7 IN RAW DEFAULT NULL,
r8 IN RAW DEFAULT NULL,
r9 IN RAW DEFAULT NULL,
r10 IN RAW DEFAULT NULL,
r11 IN RAW DEFAULT NULL,
r12 IN RAW DEFAULT NULL) RETURN RAW;
SELECT utl_raw.concat('A','41','B','42')
FROM dual;
Overlay the specified portion of target raw with overlay raw, starting from byte position pos of target and proceeding for len bytes
utl_raw.overlay(
overlay_str IN RAW,
target IN RAW,
pos IN BINARY_INTEGER DEFAULT 1,
len IN BINARY_INTEGER DEFAULT NULL,
pad IN RAW DEFAULT NULL) RETURN RAW;
SELECT utl_raw.overlay('1', 'AAABBBCCC', 4)
FROM dual;
WITH q AS (
SELECT HEXTORAW('93D90428') r FROM dual
UNION ALL
SELECT HEXTORAW('93D90428') r from dual)
SELECT r, '0x' || rawtohex(utl_raw.reverse(r)) x
FROM q;