Oracle中位元運算函數實驗

來源:互聯網
上載者:User

1.rawtohex,hextoraw

rawtohex表示將raw類型資料轉換為16進位字串(nvarchar類型,Typ=1),hextoraw表示將16進位字串轉換為raw類型。
注意:hextoraw的參數如果是字串,會當作16進位數字對待;如果是數字,也會認為是16進位而不是10進位;

SQL> select hextoraw('13'),hextoraw(13),hextoraw('D') from dual;

HEXTORAW('13') HEXTORAW(13) HEXTORAW('D')
-------------- ------------ -------------
13            13          0D

以上前兩列返回結果是相同的(十六進位13即十進位19的字串表示形式);
第三列返回'0D'是因為這樣才是一個完整位元組;
實際上hextoraw返回的值總是偶數位的,每兩位表示一個位元組;

dump一下可以證明(Typ=23表示raw類型):

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


注意以下例子:

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

雖然to_number('AB','xx')是將十六進位字串'AB'轉換為10進位數171,但是作為hextoraw參數時又被認為是16進位數了

2。utl_raw.bit_and,bitand

bitand的參數是十進位數字,將輸入參數轉化為二進位後求與,傳回值是數值型;

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,按位與結果是01000b=8(Typ=2表示number類型)

utl_raw.bit_and的參數和傳回值都是raw類型,

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.