Oracle UTL_RAW Built-In Package Versions 7.3 - 21c |
---|
Security Advisory | |||||||||||||
This built-in package was first made available when dinosaurs still roamed the earth: Oracle version 7 and there was a need for utilities for working with the RAW data type. Back then we didn't need to worry about such things as state and organized crime family attacks ... and Oracle granted EXECUTE on this package to PUBLIC. We would hope that were this package introduced today Oracle would have recognized the security implications and only granted EXECUTE to SYS and forced explicit grants to any application that requires its functionality. We do, therefore, strongly advise granting EXECUTE on UTL_RAW to GSMADMIN_INTERNAL and revoking EXECUTE from PUBLIC: In that order. If your databases have specific requirements for accessing this package explicitly grant EXECUTE to the application prior to the revoke from PUBLIC. |
|||||||||||||
Recommended Security Rules | |||||||||||||
NEVER
|
|||||||||||||
How Oracle Works | |||||||||||||
The code demo, at right, demonstrates a reasonable use if UTL_RAW as part of an anonymous block used to encrypt credit cards | set serveroutput on |
||||||||||||
UTL_RAW Package Information | |||||||||||||
AUTHID | DEFINER |
||||||||||||
Constants |
|
||||||||||||
Dependencies | SELECT name FROM dba_dependencies WHERE referenced_name = 'UTL_RAW' |
||||||||||||
Documented in Types & Packages | No | ||||||||||||
First Available | 7.3 | ||||||||||||
Security Model | Owned by SYS with EXECUTE granted to PUBLIC | ||||||||||||
Source | {ORACLE_HOME}/rdbms/admin/utlraw.sql | ||||||||||||
Subprograms |
|
||||||||||||
BIT_AND | |||||||||||||
Perform bitwise logical "and" of the values in raw r1 with raw r2 and return the "anded" result raw | utl_raw.bit_and(r1 IN RAW, r2 IN RAW) RETURN RAW; |
||||||||||||
SELECT utl_raw.bit_and('0102F3', 'F30201') |
|||||||||||||
BIT_COMPLEMENT | |||||||||||||
Perform bitwise logical "complement" of the values in raw and return the "complement'ed" result raw | utl_raw.bit_complement(r IN RAW) RETURN RAW; |
||||||||||||
SELECT utl_raw.bit_complement('0102F3') |
|||||||||||||
BIT_OR | |||||||||||||
Perform bitwise logical "or" of the values in raw r1 with raw r2 and return the "or'd" result raw | utl_raw.bit_or(r1 IN RAW, r2 IN RAW) RETURN RAW; |
||||||||||||
SELECT utl_raw.bit_or('0102F3', 'F30201') |
|||||||||||||
BIT_XOR | |||||||||||||
Perform bitwise logical "exclusive or" of the values in raw r1 with raw r2 and return the "xor'd" result raw | utl_raw.bit_xor(r1 IN RAW, r2 IN RAW) RETURN RAW; |
||||||||||||
SELECT utl_raw.bit_xor('0102F3', 'F30201') |
|||||||||||||
CAST_FROM_BINARY_DOUBLE | |||||||||||||
Return the RAW representation of a binary_double value | utl_raw.cast_from_binary_double( |
||||||||||||
SELECT utl_raw.cast_from_binary_double(123.45) |
|||||||||||||
CAST_FROM_BINARY_FLOAT | |||||||||||||
Return the RAW representation of a binary_float value | utl_raw.cast_from_binary_float( |
||||||||||||
SELECT utl_raw.cast_from_binary_float(123.45) |
|||||||||||||
CAST_FROM_BINARY_INTEGER | |||||||||||||
Return the RAW representation of a binary_integer value | utl_raw.cast_from_binary_integer( |
||||||||||||
SELECT utl_raw.cast_from_binary_integer(100) |
|||||||||||||
CAST_FROM_NUMBER | |||||||||||||
Returns the binary representation of a NUMBER in RAW | utl_raw.cast_from_number(n IN NUMBER) RETURN RAW; |
||||||||||||
SELECT utl_raw.cast_from_number(100) |
|||||||||||||
CAST_TO_BINARY_DOUBLE | |||||||||||||
Perform a casting of the binary representation of the raw into a binary_double | cast_to_binary_double( |
||||||||||||
SELECT utl_raw.cast_to_binary_double('405EDCCCCCCCCCCD') |
|||||||||||||
CAST_TO_BINARY_FLOAT | |||||||||||||
Perform a casting of the binary representation of the raw into a binary_float | utl_raw.cast_to_binary_float( |
||||||||||||
SELECT utl_raw.cast_to_binary_float('42F6E666') |
|||||||||||||
CAST_TO_BINARY_INTEGER | |||||||||||||
Perform a casting of the binary representation of the raw into a binary integer | utl_raw.cast_to_binary_integer( |
||||||||||||
SELECT utl_raw.cast_to_binary_integer('00000064') |
|||||||||||||
CAST_TO_NUMBER | |||||||||||||
Perform a casting of the binary representation of the number (in RAW) into a NUMBER | utl_raw.cast_to_number(r IN RAW) RETURN NUMBER; |
||||||||||||
SELECT utl_raw.cast_to_number('C202') |
|||||||||||||
CAST_TO_NVARCHAR2 | |||||||||||||
Converts a RAW represented using n data bytes into NVARCHAR2 with n data bytes | utl_raw.cast_to_nvarchar2(r IN RAW) RETURN NVARCHAR2; |
||||||||||||
set serveroutput on |
|||||||||||||
CAST_TO_RAW | |||||||||||||
Converts a VARCHAR2 represented using n data bytes into a RAW with n data bytes | utl_raw.cast_to_raw(r IN VARCHAR2) RETURN RAW; |
||||||||||||
SELECT utl_raw.cast_to_raw('ABC') |
|||||||||||||
CAST_TO_VARCHAR2 | |||||||||||||
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_nvarchar2(r IN RAW) RETURN VARCHAR2; |
||||||||||||
set serveroutput on |
|||||||||||||
Demo 2 | SELECT rawtohex('!4!4!4!4!4!4') FROM dual; |
||||||||||||
COMPARE | |||||||||||||
Compares raw r1 against raw r2. Returns 0 if r1 and r2 are identical, otherwise, returns the position of the first byte from r1 that does not match r2 | utl_raw.compare(r1 IN RAW, r2 IN RAW, pad IN RAW DEFAULT NULL)
RETURN NUMBER; |
||||||||||||
SELECT utl_raw.compare(utl_raw.cast_to_raw('ABC'), utl_raw.cast_to_raw('ACC')) |
|||||||||||||
CONCAT | |||||||||||||
Concatenate a set of 12 raws into a single raw (up to 32K) | utl_raw.concat(r1 IN RAW DEFAULT NULL, |
||||||||||||
SELECT utl_raw.concat('A','41','B','42') |
|||||||||||||
CONVERT | |||||||||||||
Convert raw from one character to a different character set and return the resulting raw | utl_raw.convert( |
||||||||||||
DECLARE |
|||||||||||||
COPIES | |||||||||||||
Return n copies of r concatenated together | utl_raw.copies(r IN RAW, n IN NUMBER) RETURN RAW; |
||||||||||||
SELECT utl_raw.copies('A', 6) |
|||||||||||||
LENGTH | |||||||||||||
Return the length in bytes of a raw | utl_raw.length(r IN RAW) RETURN NUMBER; |
||||||||||||
SELECT utl_raw.length('ABC') |
|||||||||||||
OVERLAY | |||||||||||||
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( |
||||||||||||
SELECT utl_raw.overlay('1', 'AAABBBCCC', 4) |
|||||||||||||
REVERSE | |||||||||||||
Reverse a byte sequence in raw r from end to end | utl_raw.reverse(r IN RAW) RETURN RAW; |
||||||||||||
SELECT utl_raw.reverse('123') |
|||||||||||||
col x format a12 |
|||||||||||||
SUBSTR | |||||||||||||
Return a substring portion of raw r beginning at pos for len bytes | utl_raw.substr(r IN RAW, |
||||||||||||
set serveroutput on |
|||||||||||||
TRANSLATE | |||||||||||||
Translate the bytes in the input r raw according to the bytes in the translation raws, from_set and to_set | utl_raw.translate( |
||||||||||||
CREATE OR REPLACE FUNCTION trans_demo(pin IN VARCHAR2) |
|||||||||||||
TRANSLITERATE | |||||||||||||
Transliterate the bytes in the input r raw according to the bytes in the transliteration raws, from_set and to_set | utl_raw.transliterate( |
||||||||||||
CREATE OR REPLACE FUNCTION tl_demo(pin IN VARCHAR2) |
|||||||||||||
XRANGE | |||||||||||||
Returns a raw containing all valid 1-byte encodings in succession beginning with the value start_byte and ending with the value end_byte | utl_raw.xrange( |
||||||||||||
SELECT utl_raw.xrange(utl_raw.cast_to_raw('A'), utl_raw.cast_to_raw('Z')) |
Related Topics |
DBMS_CRYPTO |
UTL_ENCODE |
UTL_I18N |