Update of German translation
[geany-mirror.git] / tests / ctags / hex2dec.sql
blob16b28927c762d582740f4fdccae7c8441e105816
1 rem -----------------------------------------------------------------------
2 rem URL:        http://www.orafaq.com/scripts/plsql/hex2dec.txt
3 rem Filename:   hex2dec.sql
4 rem Purpose:    Functions to convert Hex to Decimal and vice versa
5 rem Author:     Mark Malakanov, Feb-1999 + Anonymous
6 rem -----------------------------------------------------------------------
8 CREATE OR REPLACE FUNCTION hex2dec (hexnum in char) RETURN number IS
9   i                 number;
10   digits            number;
11   result            number := 0;
12   current_digit     char(1);
13   current_digit_dec number;
14 BEGIN
15   digits := length(hexnum);
16   for i in 1..digits loop
17      current_digit := SUBSTR(hexnum, i, 1);
18      if current_digit in ('A','B','C','D','E','F') then
19         current_digit_dec := ascii(current_digit) - ascii('A') + 10;
20      else
21         current_digit_dec := to_number(current_digit);
22      end if;
23      result := (result * 16) + current_digit_dec;
24   end loop;
25   return result;
26 END hex2dec;
28 show errors
30 CREATE OR REPLACE FUNCTION num2hex (N in number) RETURN varchar2 IS
31   H  varchar2(64) :='';
32   N2 integer      := N;
33 BEGIN
34   loop
35      select rawtohex(chr(N2))||H
36      into   H
37      from   dual;
39      N2 := trunc(N2 / 256);
40      exit when N2=0;
41   end loop;
42   return H;
43 END num2hex;
45 show errors
47 -- Examples:
48 select hex2dec('FF') from dual;
50 select num2hex(10) from dual;