Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: get integers in hex format

Re: get integers in hex format

From: Michel Cadot <micadot_at_netcourrier.com>
Date: Mon, 6 Dec 1999 13:53:57 +0100
Message-ID: <82gds4$p1r0$1@oceanite.cybercable.fr>


Here's a little function that converts a number to an hexadecimal string:

create or replace function to_char_hex (num integer) return varchar2 is   result varchar2(100);
  no integer := num;
  quot integer;
  remaind integer;
  function to_char_hex_digit (num integer) return varchar2 is   begin
    if num < 10 then
      return to_char(num);
    else
      return CHR(ASCII('A') + (num - 10));     end if;
  end;
begin
  if num is null then

     return null;
  end if;
  if num = 0 then

     return '0';
  end if;
  while (no > 0) loop
    quot := trunc(no/16);
    remaind := no MOD 16;
    result := to_char_hex_digit(remaind) || result;     no := quot;
  end loop;
  return result;
end;
/

Then:

v734> select to_char_hex(rownum) from dba_users;

TO_CHAR_HEX(ROWNUM)



1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
11
12
13
14

20 rows selected.

--
Have a nice day
Michel

Thomas Beetz <t.beetz_at_fnt.de> a écrit dans le message : 384B6168.F97345F1_at_fnt.de...
> Hello
>
> A simple problem:
> if i use
> select rownum from foo;
> i get
> rownum
> --------
> 1
> 2
> 3
> .
> .
> 10
> 11
> .
> .
>
> but i want
>
> rownum
> -------
> 1
> 2
> 3
> .
> .
> .
> A
> B
> .
> is there an easy way or must i write a simple function for this.
>
> Thanks thomas
>
>
>
Received on Mon Dec 06 1999 - 06:53:57 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US