UTL_RAW module
The UTL_RAW module provides a set of routines for performing bitwise operations.
The schema for this module is SYSIBMADM
The UTL_RAW module includes the following routines.
Routine Name | Description |
---|---|
BIT_AND routine | The BIT_AND routine runs a bitwise logical AND operation against the values in input1 and input2 and returns a result. |
BIT_OR routine | The BIT_OR routine runs a bitwise logical OR operation against the values in input1 and input2 and returns a result. |
BIT_XOR routine | The BIT_XOR routine runs a bitwise logical EXCLUSIVE OR operation against the values in input1 and input2 and returns a result. |
BIT_COMPLIMENT routine | The BIT_COMPLEMENT routine runs a bitwise logical COMPLEMENT operation against the values in input1 and returns a result. |
COMPARE routine | The COMPARE routine runs a COMPARE of the values in input1 against input2. |
CAST_TO_RAW function | The CAST_TO_RAW function casts a VARCHAR value to a VARBINARY value. |
CAST_TO_VARCHAR2 function | The CAST_TO_VARCHAR2 function casts a VARBINARY value to a VARCHAR2 value. |
CAST_FROM_NUMBER function | The CAST_FROM_NUMBER function casts a DECFLOAT value to a VARBINARY value. |
CAST_TO_NUMBER function | The CAST_TO_NUMBER function casts a VARBINARY value to a DECFLOAT value. |
CONCAT function | The CONCAT function concatenates up to twelve (12) VARBINARY values into a single value. |
COPIES function | The COPIES function returns the concatenated results of a VARBINARY value, repeated N times. |
LENGTH function | The LENGTH function returns the length of a VARBINARY value. |
REVERSE function | The REVERSE function reverses the order of digits in a VARBINARY value. |
SUBSTR function | The SUBSTR function returns a specified portion of a VARBINARY value. |
CAST_FROM_BINARY_DOUBLE function | The CAST_FROM_BINARY_DOUBLE function casts a DOUBLE value to a VARBINARY value. |
CAST_FROM_BINARY_FLOAT function | The CAST_FROM_BINARY_FLOAT function casts a FLOAT value to a VARBINARY value. |
CAST_FROM_BINARY_INTEGER function | The CAST_FROM_BINARY_INTEGER function casts a INTEGER value to a VARBINARY value. |
CAST_TO_BINARY_DOUBLE function | The CAST_TO_BINARY_DOUBLE function casts a VARBINARY value to a DOUBLE value. |
CAST_TO_BINARY_FLOAT function | The CAST_TO_BINARY_FLOAT function casts a VARBINARY value to a FLOAT value. |
CAST_TO_BINARY_INTEGER function | The CAST_TO_BINARY_INTEGER function casts a VARBINARY value to an INTEGER value. |
Usage Notes
In order to successfully use the UTL_RAW module for performing the bitwise operation we need to have VARBINARY as the data type for the table data values.
Examples
Example 1: The following example shows how to set up a table with a VARBINARY data
type:
db2 "create table sample(input1 VARBINARY(20) not null, input2 VARBINARY(20) not null)"
DB20000I The SQL command completed successfully.
Example 2: The following example shows how to insert data into a table that has a
VARBINARY data type:
db2 "insert into sample(input1, input2) values (bx'3131',bx'32323232')"
DB20000I The SQL command completed successfully.
db2 "insert into sample(input1, input2) values (bx'3333',bx'34343434')"
DB20000I The SQL command completed successfully.
Example 3: The following example shows how to run a BIT_AND
operation:
db2 "select sysibmadm.utl_raw.bit_and(input1,input2) from sample"
1
-----------
x'30303232'
x'30303434'
2 record(s) selected.
Example 4: The following example shows how to run a BIT_OR
operation:
db2 "select sysibmadm.utl_raw.bit_or(input1,input2) from sample"
1
-----------
x'33333232'
x'37373434'
2 record(s) selected.
Example 5: The following example shows how to run a BIT_XOR operation:
db2 "select sysibmadm.utl_raw.bit_xor(input1,input2) from sample"
1
-----------
x'03033232'
x'07073434'
2 record(s) selected.