ORACLE 36 binary and 10 binary, reciprocal conversion functions

Source: Internet
Author: User

The first part

--36 10 Binary

Create or Replace function f_36to10(STR varchar)returnintIs

ReturnValueint;
STR36 varchar(36);
Subwork varchar(1);
Workindexint;
Lenint;
Iint;

Begin

returnvalue:=0;
STR36: =' 123456789Abcdefghijklmnopqrstuvwsyz‘;
I: =1;
Len: = length(Trim(Str));

whileI <= Len Loop
Subwork: = SUBSTR(STR, I,1);
Workindex: = InStr(Str36,subwork,1,1);
ReturnValue: = ReturnValue +(Workindex * Power(len-i));
I: = i + 1;
end Loop;

return returnvalue;

end F_36to10;

Part II

--10 36 Binary

Create or Replace function f_10to36(Iint)returnVARCHAR is

RET VARCHAR2(8);
Var_mint;
var_sint;

Begin

RET: =‘‘;
var_s: = i;
whilevar_s >=36Loop
Var_m: = MoD(var_s,36);
ifVar_m <10Then
RET: = To_char(Var_m)|| Ret
Else
RET: = CHR(Var_m-10+97)|| Ret
Endif;
var_s: = trunc(var_s/36);
End Loop;
ifvar_s >0Or(var_s =0and ret =‘‘)Then
ifvar_s <10Then
RET: = To_char(var_s)|| Ret
Else
RET: = CHR(var_s-10+97)|| Ret
Endif   end  if ;
&NBSP;&NBSP;
   return  upper (ret;--lpad (ret, 8,  ' 0 ' ) ;
&NBSP;&NBSP;
END&NBSP;F_10TO36;

 

< Span style= "color: #ffffff;" >< Span style= "color: #000000;" >< Span style= "color: #000000;" > Another method, Link: http://www.cnblogs.com/jak-black/ archive/2010/09/25/1834617.html

ORACLE 36 binary and 10 binary, reciprocal conversion functions

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.