Table of Contents Previous Next


3 Built-In Packages : 3.22 UTL_RAW

The UTL_RAW package allows you to manipulate or retrieve the length of raw data types.
Note: An administrator must grant execute privileges to each user or group before they can use this package.
CAST_TO_RAW(c IN VARCHAR2)
Converts a VARCHAR2 string to a RAW value.
Converts a RAW value to a VARCHAR2 string.
CONCAT(r1 IN RAW, r2 IN RAW, r3 IN RAW,…)
Concatenate multiple RAW values into a single RAW value.
CONVERT(r IN RAW, to_charset IN VARCHAR2, from_charset IN VARCHAR2
LENGTH(r IN RAW)
SUBSTR(r IN RAW, pos IN INTEGER, len IN INTEGER)
Advanced Server's implementation of UTL_RAW is a partial implementation when compared to Oracle's version. Only those functions and procedures listed in the table above are supported.
The CAST_TO_RAW function converts a VARCHAR2 string to a RAW value. The signature is:
CAST_TO_RAW(c VARCHAR2)
The function returns a RAW value if you pass a non-NULL value; if you pass a NULL value, the function will return NULL.
The VARCHAR2 value that will be converted to RAW.
The following example uses the CAST_TO_RAW function to convert a VARCHAR2 string to a RAW value:
The CAST_TO_VARCHAR2 function converts RAW data to VARCHAR2 data. The signature is:
The function returns a VARCHAR2 value if you pass a non-NULL value; if you pass a NULL value, the function will return NULL.
The RAW value that will be converted to a VARCHAR2 value.
The following example uses the CAST_TO_VARCHAR2 function to convert a RAW value to a VARCHAR2 string:
3.22.3 CONCAT
The CONCAT function concatenates multiple RAW values into a single RAW value. The signature is:
CONCAT(r1 RAW, r2 RAW, r3 RAW,…)
The function returns a RAW value. Unlike the Oracle implementation, the Advanced Server implementation is a variadic function, and does not place a restriction on the number of values that can be concatenated.
The RAW values that CONCAT will concatenate.
The following example uses the CONCAT function to concatenate multiple RAW values into a single RAW value:
The result (the concatenated values) is then converted to VARCHAR2 format by the CAST_TO_VARCHAR2 function.
3.22.4 CONVERT
The CONVERT function converts a string from one encoding to another encoding and returns the result as a RAW value. The signature is:
CONVERT(r RAW, to_charset VARCHAR2, from_charset VARCHAR2)
The RAW value that will be converted.
from_charset
The following example uses the UTL_RAW.CAST_TO_RAW function to convert a VARCHAR2 string (Accounts) to a raw value, and then convert the value from UTF8 to LATIN7, and then from LATIN7 to UTF8:
The example returns the VARCHAR2 value, the RAW value, and the converted values:
3.22.5 LENGTH
The LENGTH function returns the length of a RAW value. The signature is:
LENGTH(r RAW)
The RAW value that LENGTH will evaluate.
The following example uses the LENGTH function to return the length of a RAW value:
The following example uses the LENGTH function to return the length of a RAW value that includes multi-byte characters:
3.22.6 SUBSTR
The SUBSTR function returns a substring of a RAW value. The signature is:
SUBSTR (r RAW, pos INTEGER, len INTEGER)
The RAW value from which the substring will be returned.
The position within the RAW value of the first byte of the returned substring.
If pos is 0 or 1, the substring begins at the first byte of the RAW value.
If pos is greater than one, the substring begins at the first byte specified by pos. For example, if pos is 3, the substring begins at the third byte of the value.
If pos is negative, the substring begins at pos bytes from the end of the source value. For example, if pos is -3, the substring begins at the third byte from the end of the value.
The following example uses the SUBSTR function to select a substring that begins 3 bytes from the start of a RAW value:
The following example uses the SUBSTR function to select a substring that starts 5 bytes from the end of a RAW value:

3 Built-In Packages : 3.22 UTL_RAW

Table of Contents Previous Next