Try this:

CREATE FUNCTION to_dec
( p_str in varchar2,
  p_from_base in number default 16 ) return number
AS
        l_num   number default 0;
--        l_hex   varchar2(16) default '0123456789ABCDEF';
        l_base   varchar2(16) default '0123456789ABCDEF....YZ';    -- fill
in the blanks
begin
        for i in 1 .. length(p_str) loop
                l_num := l_num * p_from_base +
instr(l_base,upper(substr(p_str,i,1)))-1;
        end loop;
        return l_num;
end
/

HTH, don't forget to fill in l_base local variable.  Obviosly, in your case
"p_from_base" parameter will be 36.

Igor Neyman, OCP DBA
[EMAIL PROTECTED]



----- Original Message -----
To: "Multiple recipients of list ORACLE-L" <[EMAIL PROTECTED]>
Sent: Tuesday, January 28, 2003 10:45 AM


> For very obscure reasons (read: one of those developer decisions that you
> want to use a time-machine to go back and change), we're storing some
> information in base-36 (0,1,2,3...8,9,A,B,C,...,Y,Z) in a varchar field.
> And you thought hexadecimal was fun :-)
>
> Now some bright spark would like me to build some PL/SQL to do base
> conversion - in the first instance from base 36 to base 10 (i.e decimal).
> Has anyone done something similar in the past ... that I could  borrow or
> co-opt?  As you've guessed, the deadline is yesterday :-)
>
> Ciao
> Fuzzy
> :-)
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: Grant Allen
>   INET: [EMAIL PROTECTED]
>
> Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
> San Diego, California        -- Mailing list and web hosting services
> ---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from).  You may
> also send the HELP command for other information (like subscribing).
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Igor Neyman
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Reply via email to