Get the App
SLTechnology News&Howtos  ›  Database  › 

Oracle performs binary conversion through functions

Shulou Source: shulou.com Published: 2022-06-01 09:34:45 09月28日 Update

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

Tags: Function binary decimal decimal hexadecimal length method can be passed synonym data absolute value synonym base Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Linux Redmi Huawei Xiaomi