1. rawtohex, hextoraw
Rawtohex indicates to convert raw data to a hexadecimal string (nvarchar type, Typ = 1), and hextoraw indicates to convert a hexadecimal string to the raw type.
Note: If the hextoraw parameter is a string, it will be treated as a hexadecimal number; if it is a number, it will also be considered as a hexadecimal instead of a hexadecimal value;
SQL> select hextoraw ('13'), hextoraw (13), hextoraw ('D') from dual;
HEXTORAW ('13') HEXTORAW (13) HEXTORAW ('D ')
---------------------------------------
13 13 0D
The results returned from the first two columns are the same (hexadecimal 13 is the string representation of decimal 19 );
The third column returns '0d' because it is a complete byte;
In fact, the value returned by hextoraw is always an even number, each two represents a byte;
Dump can prove (Typ = 23 indicates raw type ):
SQL> select dump (hextoraw ('13'), dump (hextoraw (13), dump (hextoraw ('D') from dual;
DUMP (HEXTORAW ('13') DUMP (HEXTORAW (13) DUMP (HEXTORAW ('D '))
---------------------------------------------------------
Typ = 23 Len = 1: 19 Typ = 23 Len = 1: 19 Typ = 23 Len = 1: 13
Note the following example:
SQL> select to_number ('AB', 'xx') from dual;
TO_NUMBER ('AB', 'xx ')
--------------------
171
SQL> select hextoraw ('AB') from dual;
HEXTORAW ('AB ')
--------------
AB
SQL> select hextoraw (to_number ('AB', 'xx') from dual;
HEXTORAW (TO_NUMBER ('AB', 'xx '))
----------------------------------------
0171
Although to_number ('AB', 'xx') is to convert the hexadecimal string 'AB' to a 10-digit number of 171, however, the hextoraw parameter is considered as a hexadecimal number.
2. Utl_raw.bit_and, bitand
The bitand parameter is a decimal number. After the input parameter is converted to a binary value, the bitand parameter is obtained. The returned value is a numeric value;
SQL> select bitand (10, 25) from dual;
BITAND (10, 25)
-------------
8
SQL> select dump (bitand (10, 25) from dual;
DUMP (BITAND (10, 25 ))
-------------------
Typ = 2 Len = 2: 193,9
10 = 1100b, 25 = 11001b. The bitwise AND result are 01000b = 8 (Typ = 2 indicates the number type)
The parameters and return values of utl_raw.bit_and are both raw type,
SQL> select utl_raw.bit_and (hextoraw ('A'), hextoraw ('19') from dual;
UTL_RAW.BIT_AND (HEXTORAW ('A '),
--------------------------------------------------------------------------------
08
SQL> select dump (utl_raw.bit_and (hextoraw ('A'), hextoraw ('19') from dual;
DUMP (UTL_RAW.BIT_AND (HEXTORAW (
--------------------------------------------------------------------------------
Typ = 23 Len = 1: 8