Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle performs binary conversion through functions

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Convert hexadecimal to decimal: to_number ()

SQL > select to_number ('axiomy dongx') from dual;TO_NUMBER (' axiomagy')-10

Convert decimal to hexadecimal: to_char ()

SQL > select to_char (10 recordings xxx') from dual;TO_CHAR (10 recordings-a

There is no way to convert binary directly. It can be realized by function:

Convert decimal to binary

CREATE OR REPLACE FUNCTION NUMBER_TO_BIT (V_NUM NUMBER) RETURN VARCHAR IS V_RTN VARCHAR (8);-- Note the length of returned column V_N1 NUMBER; V_N2 NUMBER;BEGINV_N1: = MOD (V_N1, 2); V_N1: = ABS (TRUNC (V_N1 / 2));-- absolute value of quotient V_RTN: = TO_CHAR (V_N2) | | V_RTN EXIT WHEN V_N1 = 0; END LOOP;-- returns the binary length SELECT lpad (Vogue RTN Magazine 8, 0)-- 0 INTO V_RTN FROM dual;return with less than 8 bits

Convert binary to decimal:

CREATE OR REPLACE FUNCTION BIT_TO_NUMBER (P_BIN IN VARCHAR2) RETURN NUMBER AS V_SQL VARCHAR2 (30000): = 'SELECT BIN_TO_NUM ('; V_RETURN NUMBER;BEGIN IF LENGTH (P_BIN) > = 256THEN RAISE_APPLICATION_ERROR (- 20001, 'INPUT BIN TOO lobulation'); END IF; IF LTRIM (P_BIN, '01') IS NOT NULL THEN RAISE_APPLICATION_ERROR (- 20002,' INPUT STR IS NOT VALID BIN values'); END IF; FOR I IN 1. LENGTH (P_BIN) LOOP V_SQL: = V_SQL | | SUBSTR (P_BIN, I, 1) | |','; END LOOP; V_SQL: = RTRIM (V_SQL,',') | |') FROM DUAL'; EXECUTE IMMEDIATE V_SQL INTO Vendurn; RETURN Vendurant end

Create function synonyms

Create public synonym number_to_bit for number_to_bit;grant execute on number_to_bit to public

Sixteen to two and two to sixteen can be combined with ten-to-sixteen functions and two-to-ten functions. There are no additional examples here.

ASCII code and Oracle metadata conversion functions: RAWTOHEX and HEXTORAW

SQL > select rawtohex (1) from dual;RAWTOHEX (1)-C102SQL > select rawtohex ('1') from dual;RAWTOH-31SQL > select rawtohex ('a') from dual;RAWTOH-61SQL > select rawtohex ('A') from dual;RAWTOH-41SQL > select hextoraw ('A') from dual;HE--0ASQL > select hextoraw ('1') from dual;HE--01

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report