Oracle Binary-10 binary and 2 binary mutual transfer

Source: Internet
Author: User

CREATE OR REPLACE FUNCTION number_to_bit (v_num Number) RETURN VARCHAR is V_rtnVARCHAR(8);--Note return column lengthV_n1 Number; V_n2 Number;BEGINv_n1:=V_num; LOOP v_n2:=MOD (V_N1,2); V_N1:= ABS(TRUNC (v_n1/ 2)); V_RTN:=To_char (V_N2)||V_rtn; EXITWhenv_n1= 0; END LOOP;--return binary lengthSELECT Lpad (V_rtn,8,0)     intoV_rtn from Dual;return V_rtn;
END;
CREATE OR replacefunction bit_to_number (p_bin INVARCHAR2) returnnumber asV_sqlVARCHAR2(30000) := 'SELECT Bin_to_num ('; V_return Number;BEGIN  IFLENGTH (P_bin)>=  the  ThenRaise_application_error (-20001,'INPUT BIN TOO long!');  ENDIF; IF LTRIM(P_bin,' on') is not NULL and then raise_application_error (-20002,'INPUT STR is not VALID BIN value!');  END IF; Fori 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 V_return; RETURN V_return;END;

Oracle Binary-10 binary and 2 binary mutual transfer

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.