Skip to content

UTL RAW

UTL_RAW#

The UTL_RAW package is a function which can convert or control RAW(VARBYTE) type data into a different data type.

The procedures and functions which are comprised of the UTL_RAW package are listed in the following table below.

Procedures/Functions Description
CAST_FROM_BINARY_INTEGER Converts INTERGER type of data into RAW data type
CAST_FROM_NUMBER Converts NUMERIC type of data into RAW data type
CAST_TO_BINARY_INTEGER Converts RAW type of data into BINARY_INTEGER data type
CAST_TO_NUMBER Converts RAW type of data into NUMERIC data type
CAST_TO_RAW Converts VARCHAR type of data into RAW type
CAST_TO_VARCHAR2 Converts Raw type of data into VARCHAR data type
CONCAT Connects RAW type of data
LENGTH Returns the length of data which has been input
SUBSTR Returns some of character string data which have been input.

CAST_FROM_BINARY_INTEGER#

The CAST_FROM_BINARY_INTEGER is a function converting INTEGER data type into RAW data type.

Syntax#

UTL_RAW.CAST_FROM_BINARY_INTEGER(
  n IN INTEGER,
  endianess IN INTEGER DEFAULT 1);

Parameters#

Name In/Output Data Type Description
n IN INTEGER The data which will be converted
endianess IN INTEGER This parameter is only for compatibility, and the value of this parameter can be neglected.

Return Value#

The entered INTEGER type of data is returned as RAW type.

Exception#

There is no exception.

Example#

Output 123456, which is INTEGER type by converting into RAW type.

iSQL> select utl_raw.cast_from_binary_integer(123456) from dual;
CAST_FROM_BINARY_INTEGER(123456)  
------------------------------------
40E20100          
1 row selected.

CAST_FROM_NUMBER#

The CAST_FROM_NUMBER is a function which returns NEMERIC type of data by converting into RAW type.

Syntax#

UTL_RAW.CAST_FROM_NUMBER(n IN NUMBER);

Parameter#

Name In/Output Data Type Description
n IN NUMBER The data which will be converted into RAW type

Return Value#

The entered NUMERIC type of data is returned by converting into RAW type

Exception#

There is no exception.

Example#

Output NUMBER type data 1.123456789 by converting into RAW type.

iSQL> select utl_raw.cast_from_number(1.123456789) from dual;
CAST_FROM_NUMBER(1.123456789)
------------------------------------------------------------------------------------
07C1010C22384E5A
1 row selected.

CAST_TO_BINARY_INTEGER#

The CAST_TO_BINARY_INTEGER is a function which returns RAW type of data by converting into INTEGER type.

Syntax#

UTL_RAW.CAST_TO_BINARY_INTEGER(
  r IN RAW(8),
  endianess IN INTEGER DEFAULT 1);

Parameters#

Name In/Output Data Type Description
r IN RAW(8) The data which will be converted as INTEGER type.
endianess IN INTEGER This parameter is only for compatibility, and the value is neglected.

Return Value#

The entered RAW type of data is returned as INTEGER type.

Exception#

There is no exception.

Example#

Output 40E20100, which is RAW type by converting into INTEGER.

iSQL> select utl_raw.cast_to_binary_integer('40E20100') from dual;
CAST_TO_BINARY_INTEGER('40E20100')
-------------------------------------
123456      
1 row selected.

CAST_TO_NUMBER#

The CAST_TO_NUMBER is a function which returns RAW type of data by converting it into NUMERIC type.

Syntax#

UTL_RAW.CAST_TO_NUMBER(r IN RAW(32767));

Parameter#

Name IN/Output Data Type Description
r IN RAW(32767) The data which will be converted into NUMERIC type

Return Value#

The entered RAW type of data is returned as NUMERIC type.

Exception#

There is no exception.

Example#

Output RAW type 07C1010C22384E5A by converting NUMBER.

iSQL> select utl_raw.cast_to_number('07C1010C22384E5A') from dual;
CAST_TO_NUMBER('07C1010C22384E5A')
-------------------------------------
1.12345679  
1 row selected.

CAST_TO_RAW#

The CAST_TO_RAW is a function returning VARCHAR type of data by converting into RAW(VARBYTE) type.

Syntax#

UTL_RAW.CAST_TO_RAW(c IN VARCHAR(32767));

Parameter#

Name In/Output Data Type Description
c IN VARCHAR(32767) The data which will be converted into RAW type.

Return Value#

The entered data is returned as RAW type.

Exception#

There is no exception.

Emample#

Output 'altibase' with RAW.

iSQL> select cast(utl_raw.cast_to_raw('altibase') as raw(10)) from dual;
CAST(UTL_RAW.CAST_TO_RAW('altibase') as RA  
----------------------------------------------
0800616C746962617365  
1 row selected.

CAST_TO_VARCHAR2#

The CAST_TO_VARCHAR2 is a function which returns RAW type of data by converting it into VARCHAR type.

Syntax#

UTL_RAW.CAST_TO_VARCHAR2(c IN RAW(32767));

Parameter#

Name In/Out Data Type Description
c IN RAW(32767) The data which will be converted into VARCHAR type

Return Value#

The entered data is returned by converting it into VARCHAR type.

Exception#

There is no exception.

Example#

Output 0800616C746962617365, the RAW type of data, by converting it into VARCHAR type.

iSQL> select cast(utl_raw.cast_to_varchar2('0800616C746962617365') as varchar(8)) from dual;
CAST(UTL_RAW.CAST_TO_VARCHAR2('0800616C746  
----------------------------------------------
altibase  
1 row selected.

CONCAT#

The CONCAT is a function returning the RAW(VARBYTE) data which has been input in parameters by concatenating.

Syntax#

UTL_RAW.CONCAT(
  r1 IN RAW(32767) DEFAULT NULL,
  r2 IN RAW(32767) DEFAULT NULL,
  r3 IN RAW(32767) DEFAULT NULL,
  r4 IN RAW(32767) DEFAULT NULL,
  r5 IN RAW(32767) DEFAULT NULL,
  r6 IN RAW(32767) DEFAULT NULL,
  r7 IN RAW(32767) DEFAULT NULL,
  r8 IN RAW(32767) DEFAULT NULL,
  r9 IN RAW(32767) DEFAULT NULL,
  r10 IN RAW(32767) DEFAULT NULL,
  r11 IN RAW(32767) DEFAULT NULL,
  r12 IN RAW(32767) DEFAULT NULL);

Parameter#

Name In/Output Data Type Description
r1...r12 IN RAW(32767) RAW type data The data can input from r1 to r12.

Return Value#

The data connected from r1 to r12 is returned.

Exception#

There is no exception.

Example#

Output the RAW type by concatenating AA and BB.

iSQL> select cast(utl_raw.concat(raw'aa', raw'bb') as raw(4)) from dual;
CAST(UTL_RAW.CONCAT(RAW'aa', RAW'bb') as R  
----------------------------------------------
AABB      
1 row selected.

LENGTH#

The LENGTH is a function returning the length of input RAW type data.

Syntax#

UTL_RAW.LENGTH(r IN RAW(32767));

Parameter#

Name In/Output Data Type Description
c IN RAW(32767) The RAW type data which will return the length

Return Value#

The length of RAW data, which has been input, is returned.

Exception#

There is no exception.

Example#

Output characteristic 'altibase' with the length of RAW data type.

iSQL> select utl_raw.length(utl_raw.cast_to_raw('altibase')) from dual;
LENGTH(UTL_RAW.CAST_TO_RAW('altibase'))
------------------------------------------
12          
1 row selected.

SUBSTR#

The SUBSTR is a function which returns some parts of a character string in RAW type data which has been input.

Syntax#

UTL_RAW.SUBSTR(
  r IN RAW(32767),
  pos IN INTEGER,
  len IN INTEGER);

Parameters#

Name In/Output Data Type Description
r IN RAW(32767) The input data
pos IN INTEGER The position in which begins returning data. If the value is a positive number, it begins from the front of the input data whereas it begins at the end of data if the value is a negative number.
len IN INTEGER The length of the data which will be returned. If omitted, all the character string is returned to the end of data.

Return Value#

The specified length from the beginning point of input data of RAW data is returned

Exception#

There is no exception.

Example#

Return the length which is the second from the first of 0102030405 RAW type data.

iSQL> select cast(utl_raw.substr('0102030405',1,2) as raw(2)) from dual;
CAST(UTL_RAW.SUBSTR('0102030405',1,2) as R  
----------------------------------------------
0102