Oracle median function test

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.