From oracle-l-bounce@freelists.org  Thu Jul 15 22:38:20 2004
Return-Path: <oracle-l-bounce@freelists.org>
Received: from air189.startdedicated.com (root@localhost)
 by orafaq.com (8.11.6/8.11.6) with ESMTP id i6G3c5926287
 for <oracle-l@orafaq.com>; Thu, 15 Jul 2004 22:38:15 -0500
X-ClientAddr: 206.53.239.180
Received: from turing.freelists.org (freelists-180.iquest.net [206.53.239.180])
 by air189.startdedicated.com (8.11.6/8.11.6) with ESMTP id i6G3bs626273
 for <oracle-l@orafaq.com>; Thu, 15 Jul 2004 22:38:04 -0500
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP
 id 371BD72C45C; Thu, 15 Jul 2004 22:18:02 -0500 (EST)
Received: from turing.freelists.org ([127.0.0.1])
 by localhost (turing [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
 id 27410-78; Thu, 15 Jul 2004 22:18:02 -0500 (EST)
Received: from turing (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP
 id 7673F72C37D; Thu, 15 Jul 2004 22:18:01 -0500 (EST)
Received: with ECARTIS (v1.0.0; list oracle-l); Thu, 15 Jul 2004 22:16:37 -0500 (EST)
X-Original-To: oracle-l@freelists.org
Delivered-To: oracle-l@freelists.org
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6640972C01C
 for <oracle-l@freelists.org>; Thu, 15 Jul 2004 22:16:37 -0500 (EST)
Received: from turing.freelists.org ([127.0.0.1])
 by localhost (turing [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
 id 27410-56 for <oracle-l@freelists.org>;
 Thu, 15 Jul 2004 22:16:37 -0500 (EST)
Received: from smtp810.mail.sc5.yahoo.com (smtp810.mail.sc5.yahoo.com [66.163.170.80])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with SMTP id DD0E972C014
 for <oracle-l@freelists.org>; Thu, 15 Jul 2004 22:16:36 -0500 (EST)
Received: from unknown (HELO medo.noip.com) (gogala@sbcglobal.net@64.252.251.229 with login)
  by smtp810.mail.sc5.yahoo.com with SMTP; 16 Jul 2004 03:41:45 -0000
Date: Thu, 15 Jul 2004 23:41:44 -0400
From: Mladen Gogala <gogala@sbcglobal.net>
To: oracle-l@freelists.org
Subject: Re: How do you display hex via SQL
Message-ID: <20040716034144.GA3828@medo.noip.com>
References: <BAY22-F15f7LXXcbdFk00002ccb@hotmail.com>
Mime-Version: 1.0
Content-type: text/plain; charset=ISO-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <BAY22-F15f7LXXcbdFk00002ccb@hotmail.com> (from wazhomer@hotmail.com on Thu, Jul 15, 2004 at 22:26:44 -0400)
X-Mailer: Balsa 2.0.18
Lines: 97
X-Virus-Scanned: by amavisd-new at freelists.org
X-archive-position: 5285
X-ecartis-version: Ecartis v1.0.0
Sender: oracle-l-bounce@freelists.org
Errors-To: oracle-l-bounce@freelists.org
X-original-sender: gogala@sbcglobal.net
Precedence: normal
Reply-To: oracle-l@freelists.org
X-list: oracle-l
X-Virus-Scanned: by amavisd-new at freelists.org


On 07/15/2004 10:26:44 PM, Warren Homer wrote:
> Hi ,
> 
> is there a way via Oracle SQL to display the hex representation of a number.
> 
> e.g select hex(57) from dual;
> 
This is a simple programming excercise. Here is how it goes:

PROMPT CREATE OR REPLACE PACKAGE myutil

CREATE OR REPLACE PACKAGE myutil
as
function num2hex(num number) return varchar2 deterministic;
end;
/

PROMPT CREATE OR REPLACE PACKAGE BODY myutil

CREATE OR REPLACE PACKAGE BODY myutil as
type arr is table of char(1);
digits arr;
function num2hex(num number) return varchar2
is
quot number;
rem  number;
dig  char(1);
begin
   rem:=mod(num,16);
   dig:=digits(rem+1);
   quot:=floor(num/16);
   if (num>0) then
      return(num2hex(quot)||dig);
   else
      return(NULL);
   end if;
end;
begin
digits:=arr('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
end;
/


Here comes the demonstration:
SQL>  select myutil.num2hex(&num)  from dual;
Enter value for num: 57
old   1:  select myutil.num2hex(&num)  from dual
new   1:  select myutil.num2hex(57)  from dual
 
MYUTIL.NUM2HEX(57)
--------------------------------------------------------------------------------
39
 

SQL> /
Enter value for num: 64
old   1:  select myutil.num2hex(&num)  from dual
new   1:  select myutil.num2hex(64)  from dual
 
MYUTIL.NUM2HEX(64)
--------------------------------------------------------------------------------
40
 
SQL> /
Enter value for num: 256
old   1:  select myutil.num2hex(&num)  from dual
new   1:  select myutil.num2hex(256)  from dual
 
MYUTIL.NUM2HEX(256)
--------------------------------------------------------------------------------
100
 
SQL> /
Enter value for num: 65535
old   1:  select myutil.num2hex(&num)  from dual
new   1:  select myutil.num2hex(65535)  from dual
 
MYUTIL.NUM2HEX(65535)
--------------------------------------------------------------------------------
FFFF
 
SQL> /
Enter value for num: 1048576
old   1:  select myutil.num2hex(&num)  from dual
new   1:  select myutil.num2hex(1048576)  from dual
 
MYUTIL.NUM2HEX(1048576)
--------------------------------------------------------------------------------
100000
 
SQL>


-- 
Mladen Gogala
Oracle DBA
----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request@freelists.org
put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

