日期:2014-05-16 浏览次数:20407 次
create or replace function number_2_bit(v_num number) return varchar is v_rtn varchar(2000); v_n1 number; v_n2 number;begin v_n1 := v_num; loop v_n2 := mod(v_n1, 2); v_n1 := trunc(v_n1 / 2); v_rtn := to_char(v_n2) || v_rtn; exit when v_n1 = 0; end loop; return v_rtn;end; sql> select bit_2_number('10001100000000011001111111111') from dual; ------------------------------ 293614591
?
create or replace function bit_2_number(v_char varchar) return number is v_rtn number(10); v_n1 number; v_n2 number; Begin Select sum (data1) Into v_rtn From (select substr (v_char,rownum,1)* power(2,length(v_char)-rownum) data1 From dual Connect by rownum<=length(v_char) ; Return v_rtn; End; sql> select number_2_bit(571231007) from dual; ------------------------------ 100010000011000100101100011111
?