terça-feira, 28 de dezembro de 2010

Octal para Decimal

CREATE OR REPLACE FUNCTION oct2dec (octval in char) RETURN number IS
  i                 number;
  digits            number;
  result            number := 0;
  current_digit     char(1);
  current_digit_dec number;
BEGIN
  digits := length(octval);
  for i in 1..digits loop
     current_digit := SUBSTR(octval, i, 1);
     current_digit_dec := to_number(current_digit);
     result := (result * 8) + current_digit_dec;
  end loop;
  return result;
END oct2dec;
/
 
SQL> SELECT oct2dec(127662) FROM dual;
OCT2DEC(127662)
---------------
          44978

Nenhum comentário :

Postar um comentário

Related Posts Plugin for WordPress, Blogger...