The UTL_RAW
package provides SQL functions for manipulating RAW
datatypes.
This chapter contains the following topics:
Overview
Operational Notes
This package is necessary because normal SQL functions do not operate on RAWs
, and PL/SQL does not allow overloading between a RAW
and a CHAR
datatype. UTL_RAW
also includes subprograms that convert various COBOL number formats to, and from, RAWs
.
UTL_RAW
is not specific to the database environment, and it may actually be used in other environments. For this reason, the prefix UTL has been given to the package, instead of DBMS.
UTL_RAW
allows a RAW
"record" to be composed of many elements. By using the RAW
datatype, character set conversion will not be performed, keeping the RAW
in its original format when being transferred through remote procedure calls.
With the RAW
functions, you can manipulate binary data that was previously limited to the hextoraw
and rawtohex
functions.
Note:
Notes on data types:The PLS_INTEGER
and BINARY_INTEGER
data types are identical. This document uses BINARY_INTEGER
to indicate data types in reference information (such as for table types, record types, subprogram parameters, or subprogram return values), but may use either in discussion and examples.
The INTEGER
and NUMBER(38)
data types are also identical. This document uses INTEGER
throughout.
Table 233-1 UTL_RAW Package Subprograms
Subprogram | Description |
---|---|
Performs bitwise logical "and" of the values in |
|
Performs bitwise logical "complement" of the values in |
|
Performs bitwise logical "or" of the values in |
|
Performs bitwise logical "exclusive or" of the values in |
|
Returns the |
|
Returns the |
|
Returns the |
|
Returns the |
|
Casts the |
|
Casts the |
|
Casts the |
|
Casts the |
|
Converts a |
|
Converts a |
|
Converts a |
|
Compares |
|
Concatenates up to 12 |
|
Converts |
|
Returns |
|
Returns the length in bytes of a |
|
Overlays the specified portion of target |
|
Reverses a byte sequence in |
|
Returns |
|
Translates the bytes in the input |
|
Converts the bytes in the input |
|
Returns a |
This function performs bitwise logical "and" of the values in RAW
r1
with RAW
r2
and returns the "anded" result RAW
.
This function performs bitwise logical "complement" of the values in RAW
r
and returns the complement'ed result RAW
. The result length equals the input RAW
r
length.
This function performs bitwise logical "or" of the values in RAW
r1 with RAW
r2 and returns the or'd result RAW
.
This function performs bitwise logical "exclusive or" of the values in RAW
r1
with RAW
r2
and returns the xor'd result RAW
.
This function returns the RAW
binary representation of a BINARY_DOUBLE
value.
UTL_RAW.CAST_FROM_BINARY_DOUBLE( n IN BINARY_DOUBLE, endianess IN PLS_INTEGER DEFAULT 1) RETURN RAW;
Table 233-10 CAST_FROM_BINARY_DOUBLE Function Parameters
Parameter | Description |
---|---|
|
|
|
A |
An 8-byte binary_double
value maps to the IEEE 754 double-precision format as follows:
byte 0: bit 63 ~ bit 56 byte 1: bit 55 ~ bit 48 byte 2: bit 47 ~ bit 40 byte 3: bit 39 ~ bit 32 byte 4: bit 31 ~ bit 24 byte 5: bit 23 ~ bit 16 byte 6: bit 15 ~ bit 8 byte 7: bit 7 ~ bit 0
The parameter endianess describes how the bytes of BINARY_DOUBLE
are mapped to the bytes of RAW
. In the following matrix, rb0 ~ rb7 refer to the bytes in raw and db0 ~ db7 refer to the bytes in BINARY_DOUBLE.
rb0 | rb1 | rb2 | rb3 | rb4 | rb5 | rb6 | rb7 | |
---|---|---|---|---|---|---|---|---|
big_endian | db0 |
db1 |
db2 |
db3 |
db4 |
db5 |
db6 |
db7 |
little_endian | db7 |
db6 |
db5 |
db4 |
db3 |
db2 |
db1 |
db0 |
In case of machine-endian, the 8 bytes of the BINARY_DOUBLE
argument are copied straight across into the RAW
return value. The effect is the same if the user has passed big_endian
on a big-endian machine, or little_endian
on a little-endian machine.
This function returns the RAW
binary representation of a BINARY_FLOAT
value.
UTL_RAW.CAST_FROM_BINARY_FLOAT( n IN BINARY_FLOAT, endianess IN PLS_INTEGER DEFAULT 1) RETURN RAW;
Table 233-11 CAST_FROM_BINARY_FLOAT Function Parameters
Parameter | Description |
---|---|
|
|
|
A |
The binary representation (RAW) of the BINARY_FLOAT
value, or NULL
if the input is NULL
.
A 4-byte binary_float
value maps to the IEEE 754 single-precision format as follows:
byte 0: bit 31 ~ bit 24 byte 1: bit 23 ~ bit 16 byte 2: bit 15 ~ bit 8 byte 3: bit 7 ~ bit 0
The parameter endianess describes how the bytes of BINARY_FLOAT
are mapped to the bytes of RAW
. In the following matrix, rb0 ~ rb3 refer to the bytes in RAW
and fb0 ~ fb3 refer to the bytes in BINARY_FLOAT
.
rb0 | rb1 | rb2 | rb3 | |
---|---|---|---|---|
big_endian | fb0 | fb1 | fb2 | fb3 |
little_endian | fb3 | fb2 | fb1 | fb0 |
In case of machine-endian, the 4 bytes of the BINARY_FLOAT
argument are copied straight across into the RAW
return value. The effect is the same if the user has passed big_endian
on a big-endian machine, or little_endian
on a little-endian machine.
This function returns the RAW
binary representation of a BINARY_INTEGER
value.
UTL_RAW.CAST_FROM_BINARY_INTEGER ( n IN BINARY_INTEGER endianess IN PLS_INTEGER DEFAULT BIG_ENDIAN) RETURN RAW;
Table 233-12 CAST_FROM_BINARY_INTEGER Function Parameters
Parameter | Description |
---|---|
|
|
|
A |
This function casts the RAW binary representation of a BINARY_DOUBLE
into a BINARY_DOUBLE
.
UTL_RAW.CAST_TO_BINARY_DOUBLE ( r IN RAW endianess IN PLS_INTEGER DEFAULT 1) RETURN BINARY_DOUBLE;
If the RAW
argument is more than 8 bytes, only the first 8 bytes are used and the rest of the bytes are ignored. If the result is -0
, +0
is returned. If the result is NaN
, the value BINARY_DOUBLE_NAN
is returned.
If the RAW
argument is less than 8 bytes, a VALUE_ERROR
exception is raised.
An 8-byte binary_double value maps to the IEEE 754 double-precision format as follows:
byte 0: bit 63 ~ bit 56 byte 1: bit 55 ~ bit 48 byte 2: bit 47 ~ bit 40 byte 3: bit 39 ~ bit 32 byte 4: bit 31 ~ bit 24 byte 5: bit 23 ~ bit 16 byte 6: bit 15 ~ bit 8 byte 7: bit 7 ~ bit 0
The parameter endianess describes how the bytes of BINARY_DOUBLE
are mapped to the bytes of RAW
. In the following matrix, rb0 ~ rb7 refer to the bytes in raw and db0 ~ db7 refer to the bytes in BINARY_DOUBLE.
rb0 | rb1 | rb2 | rb3 | rb4 | rb5 | rb6 | rb7 | |
---|---|---|---|---|---|---|---|---|
big_endian | db0 |
db1 |
db2 |
db3 |
db4 |
db5 |
db6 |
db7 |
little_endian | db7 |
db6 |
db5 |
db4 |
db3 |
db2 |
db1 |
db0 |
In case of machine-endian, the 8 bytes of the RAW
argument are copied straight across into the BINARY_DOUBLE
return value. The effect is the same if the user has passed big_endian
on a big-endian machine, or little_endian
on a little-endian machine.
This function casts the RAW binary representation of a BINARY_FLOAT
into a BINARY_FLOAT
.
UTL_RAW.CAST_TO_BINARY_FLOAT ( r IN RAW endianess IN PLS_INTEGER DEFAULT 1) RETURN BINARY_FLOAT;
If the RAW
argument is more than 4 bytes, only the first 4 bytes are used and the rest of the bytes are ignored. If the result is -0, +0 is returned. If the result is NaN, the value BINARY_FLOAT_NAN
is returned.
If the RAW
argument is less than 4 bytes, a VALUE_ERROR
exception is raised.
A 4-byte binary_float
value maps to the IEEE 754 single-precision format as follows:
byte 0: bit 31 ~ bit 24 byte 1: bit 23 ~ bit 16 byte 2: bit 15 ~ bit 8 byte 3: bit 7 ~ bit 0
The parameter endianess describes how the bytes of BINARY_FLOAT
are mapped to the bytes of RAW
. In the following matrix, rb0 ~ rb3 refer to the bytes in RAW
and fb0 ~ fb3 refer to the bytes in BINARY_FLOAT
.
rb0 | rb1 | rb2 | rb3 | |
---|---|---|---|---|
big_endian | fbo |
fb1 |
fb2 |
fb3 |
little_endian | fb3 |
fb2 |
fb1 |
fb0 |
In case of machine-endian, the 4 bytes of the RAW
argument are copied straight across into the BINARY_FLOAT
return value. The effect is the same if the user has passed big_endian
on a big-endian machine, or little_endian
on a little-endian machine.
This function casts the RAW binary representation of a BINARY_INTEGER
into a BINARY_INTEGER
.
UTL_RAW.CAST_TO_BINARY_INTEGER ( r IN RAW endianess IN PLS_INTEGER DEFAULT BIG_ENDIAN) RETURN BINARY_INTEGER;
This function casts the RAW binary representation of a NUMBER
into a NUMBER
.
This function converts a RAW
value represented using some number of data bytes into an NVARCHAR2
value with that number of data bytes.
Note:
When casting to aNVARCHAR2
, the current Globalization Support character set is used for the characters within that NVARCHAR2
value.This function converts a VARCHAR2
value represented using some number of data bytes into a RAW
value with that number of data bytes. The data itself is not modified in any way, but its data type is recast to a RAW
data type.
This function converts a RAW
value represented using some number of data bytes into a VARCHAR2
value with that number of data bytes.
Note:
When casting to aVARCHAR2
, the current Globalization Support character set is used for the characters within that VARCHAR2
.This function compares two RAW
values. If they differ in length, then the shorter is extended on the right according to the optional pad
parameter.
This function concatenates up to 12 RAWs
into a single RAW
. If the concatenated size exceeds 32K, then an error is returned
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;
This function converts RAW
r
from character set from_charset
to character set to_charset
and returns the resulting RAW
.
Both from_charset
and to_charset
must be supported character sets defined to the Oracle server.
This function overlays the specified portion of target RAW
with overlay_str
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;
Table 233-34 OVERLAY Function Parameters
Parameters | Description |
---|---|
|
Byte-string used to overlay target |
|
Byte-string which is to be overlaid |
|
Position in target (numbered from 1) to start overlay |
|
The number of target bytes to overlay |
|
Pad byte used when overlay |
If overlay_str
has less than len
bytes, then it is extended to len
bytes using the pad
byte. If overlay_str
exceeds len
bytes, then the extra bytes in overlay_str
are ignored. If len
bytes beginning at position pos
of target
exceeds the length of target
, then target
is extended to contain the entire length of overlay_str
.
If
len
is specified, it must be greater than or equal to 0
. If pos
is specified, it must be greater than or equal to 1
. If pos
exceeds the length of target
, then target
is padded with pad
bytes to position pos
, and target
is further extended with overlay_str
bytes.
This function reverses a byte sequence in RAW
r
from end to end. For example, x'0102F3' would be reversed to x'F30201', and 'xyz' would be reversed to 'zyx'.The result length is the same as the input RAW
length.
This function returns len
bytes, starting at pos
from RAW
r
.
UTL_RAW.SUBSTR ( r IN RAW, pos IN BINARY_INTEGER, len IN BINARY_INTEGER DEFAULT NULL) RETURN RAW;
If pos
is positive, then SUBSTR
counts from the beginning of r
to find the first byte. If pos
is negative, then SUBSTR
counts backward from the end of the r
. The value pos
cannot be 0.
If len
is omitted, then SUBSTR
returns all bytes to the end of r
. The value len
cannot be less than 1.
This function translates the bytes in the input RAW
r
according to the bytes in the translation RAWs
from_set
and to_set
. If a byte in r
has a matching byte in from_set
, then it is replaced by the byte in the corresponding position in to_set
, or deleted.
Bytes in r
, but undefined in from_set
, are copied to the result. Only the first (leftmost) occurrence of a byte in from_set
is used. Subsequent duplicates are not scanned and are ignored.
UTL_RAW.TRANSLATE ( r IN RAW, from_set IN RAW, to_set IN RAW) RETURN RAW;
Note:
Be aware thatto_set
and from_set
are reversed in the calling sequence compared to TRANSLITERATE
.If to_set
is shorter than from_set
, the extra from_set
bytes have no corresponding translation bytes. Bytes from the input RAW
that match any such from_set
bytes are not translated or included in the result. They are effectively translated to NULL
.
If to_set
is longer than from_set
, the extra to_set
bytes are ignored.
If a byte value is repeated in from_set
, the repeated occurrence is ignored.
Note:
Differences from the TRANSLITERATE Function:The from_set
parameter comes before the to_set
parameter in the calling sequence.
Bytes from r
that appear in from_set
but have no corresponding values in to_set
are not translated or included in the result.
The resulting RAW
value may be shorter than the input RAW
value.
Note that TRANSLATE
and TRANSLITERATE
only differ in functionality when to_set
has fewer bytes than from_set
.
This function converts the bytes in the input RAW
r
according to the bytes in the transliteration RAWs
from_set
and to_set
. Successive bytes in r
are looked up in the from_set
, and, if not found, copied unaltered to the result RAW
. If found, then they are replaced in the result RAW
by either corresponding bytes in the to_set
, or the pad
byte when no correspondence exists.
Bytes in r
, but undefined in from_set
, are copied to the result. Only the first (leftmost) occurrence of a byte in from_set
is used. Subsequent duplicates are not scanned and are ignored. The result RAW
is always the same length as r
.
UTL_RAW.TRANSLITERATE ( r IN RAW, to_set IN RAW DEFAULT NULL, from_set IN RAW DEFAULT NULL, pad IN RAW DEFAULT NULL) RETURN RAW;
Note:
Be aware thatto_set
and from_set
are reversed in the calling sequence compared to TRANSLATE
.Table 233-48 TRANSLITERATE Function Parameters
Parameter | Description |
---|---|
|
|
|
|
|
|
|
1 byte used when to-set is shorter than the |
If to_set
is shorter than from_set
, the extra from_set
bytes have no corresponding conversion bytes. Bytes from the input RAW
that match any such from_set
bytes are converted in the result to the pad byte instead.
If to_set
is longer than from_set
, the extra to_set
bytes are ignored.
If a byte value is repeated in from_set
, the repeated occurrence is ignored.
Note:
Differences from the TRANSLATE Function:The to_set
parameter comes before the from_set
parameter in the calling sequence.
Bytes from r
that appear in from_set
but have no corresponding values in to_set
are replaced by pad in the result.
The resulting RAW
value always has the same length as the input RAW
value.
Note that TRANSLATE
and TRANSLITERATE
only differ in functionality when to_set
has fewer bytes than from_set
.
This function returns a RAW value
containing the succession of one-byte encodings beginning and ending with the specified byte-codes. The specified byte-codes must be single-byte RAW
values. If the start_byte
value is greater than the end_byte
value, then the succession of resulting bytes begins with start_byte
, wraps through x'FF'
back to x'00'
, then ends at end_byte
.