UTL_RAW Implementation
1. Purpose
ivorysql_ora provides Oracle-compatible UTL_RAW.CAST_TO_RAW to return text bytes in the database encoding as RAW. For examples, see UTL_RAW Package.
2. Implementation
2.1. Calls and Encoding
The package specification declares CAST_TO_RAW(c IN VARCHAR2) RETURN RAW. Its PL/iSQL body evaluates the following expression.
RETURN pg_catalog.convert_to(c::text, pg_catalog.getdatabaseencoding());
-
Cast the input to
textand retrieve the database encoding withgetdatabaseencoding(). -
convert_to()uses the database encoding as its source. The target is also the database encoding, so the output preserves the original bytes. For example,éstored in aLATIN1database yields the single bytee9. -
convert_to()producesbytea, which the package returns as its declared type,sys.raw.sys.rawis a domain overbytea.
2.2. Display and Null Values
RAW uses the bytea_output display format. By default it appears as a hexadecimal string prefixed with \x. Use RAWTOHEX to return hexadecimal text.
convert_to() returns NULL for NULL input. The outcome for an empty string depends on the value passed to the package function, yielding either NULL or a zero-byte RAW value.
3. Related Files and Tests
Paths are relative to contrib/ivorysql_ora/.
| File | Role |
|---|---|
|
Package specification, byte-order constants, and PL/iSQL function body. |
|
Module description. The package body performs the conversion through built-in functions. |
|
Includes the package definition in the extension installation script. |
|
Regression coverage for ASCII, multibyte text, null input, the error when selecting a package constant in SQL, and byte preservation in |