orafce_ext
is an extension for orafce. It provides the external capability to support the Oracle interface and the UTL_RAW
utility.
Enable orafce
and orafce_ext
in each desired database.
CREATE EXTENSION orafce;
CREATE EXTENSION orafce_ext;
UTL_RAW
supports the RAW
datatype, enabling users to store and manipulate binary data.
ImportantThe
max_length
for theRAW
dataype is1GB
inorafce_ext
, compared to32767
in Oracle.
All functions in UTL_RAW
fall under the utl_raw
namespace:
utl_raw.cast_to_raw(c IN VARCHAR2)
utl_raw.cast_to_varchar2(r IN RAW)
utl_raw.concat(r1 IN RAW, r2 IN RAW, r3 IN RAW, ...)
utl_raw.convert(r IN RAW, to_charset IN VARCHAR2, from_charset IN VARCHAR2)
utl_raw.length(r IN RAW)
utl_raw.substr(r IN RAW, pos IN INTEGER, len IN INTEGER)
This function converts a VARCHAR2
value into a RAW
value.
NoteThis example applies to
orafce
v3.7. For Greenplum Database 6, usevarchar2
instead oforacle.varchar2
.
testdb=# SELECT utl_raw.cast_to_raw('abc'::varchar2);
cast_to_raw
-------------
\x616263
(1 row)
This function converts a RAW
value into a VARCHAR2
value.
testdb=# SELECT utl_raw.cast_to_varchar2('abc'::raw);
cast_to_varchar2
------------------
abc
(1 row)
This function concatenates multiple RAW
values into a single RAW
value.
testdb=# SELECT utl_raw.concat('a'::raw, 'b'::raw, 'c'::raw);
concat
----------
\x616263
(1 row)
This function converts RAW r
from character set from_charset
to character set to_charset
and returns the resulting RAW
.
testdb=# select 'abc'::raw;
raw
----------------
\xe697a0e6958c
(1 row)
testdb=# SELECT utl_raw.convert('abc'::raw, 'GBK', 'UTF-8');
convert
------------
\xcedeb5d0
(1 row)
This function returns the length in bytes of a RAW
.
testdb=# select utl_raw.length('abc'::raw);
length
--------
6
(1 row)
This function returns the substring of a RAW
.
utl_raw.substr(r IN RAW, pos IN INTEGER, len IN INTEGER)
Where:
The value of pos
cannot be 0
and cannot exceed length(r)
.
pos
is positive, SUBSTR
counts from the beginning of r
to find the first byte.pos
is negative, SUBSTR
counts backward from the end of r
.The value of len
cannot be less than 1
and cannot exceed length(r) - (pos - 1)
.
len
is omitted, SUBSTR
returns all bytes to the end of r
.testdb=# SELECT utl_raw.substr('abc'::raw, 1, 2);
substr
--------
\x6162
(1 row)
To return the substring without length:
testdb=# SELECT utl_raw.substr('abc'::raw, 1);
substr
----------
\x616263
(1 row)