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: RAW / NUMBER convertion

Re: RAW / NUMBER convertion

From: <prochak_at_my-dejanews.com>
Date: Wed, 26 Aug 1998 18:15:51 GMT
Message-ID: <6s1jcm$pca$1@nnrp1.dejanews.com>


In article <35e31796.0_at_informer.hixnet.co.za>,   "John Bester" <johnb_at_iconnect.co.za> wrote:
> Hi,
>
> I have a 12byte raw field of which I want to convert the 1st 2 bytes into a
> number, increment it, and save it in a trigger. Why I need to do this is
> complicated - I just do not have a choice.
>
> I can convert a RAW to a HEX string using the HEXTORAW function. Then I can
> use SUBSTR to get the portion I need - but after that I am stuck. The
> TO_NUMBER function does not have formatting options for HEX numbers, and
> converting it back to a RAW and performing a TO_NUMBER on that also does not
> work.
>
> Any help will be greatly appreciated.
> ---
> John Bester
> johnb_at_iconnect.co.za
>
>

You could write a simple PL/SQL function to do this. In the HEX string version you have 4characters. Use substr() to get each one and convert it to a number. Say c4 is a CHAR containing the first character. The change this HEX digit to a number value in v4 by a simple DECODE():

v4 = DECODE(upper(c4),

               '0',0, '1',1, '2',2, '3',3, '4',4,
               '5',5, '6',6, '7',7, '8',8, '9',9,
               'A',10, 'B',11, 'C',12, 'D',13, 'E',14, 'F',15 );

Then those 4 numbers (each valued 0-15) are combined according to their original positions:

value = 16*16*16*v4 + 16*16*v3 + 16*v2 + v1

Where the original 4 HEX characters were ABCD, then the A is position 4, the B is position 3, the C is position 2 and D is position 1. Use that as your test and the decimal value should be 43981.

That's the definition of HEXidecmal, each digit position is a power of 16 larger than its neighbor and each digit is a value 0 to 15.

(This must be in a package somewhere. If not, maybe I publish one.)

If you need further help, contact me or post to the group again.

--
Ed Prochak
Magic Interface, Ltd.
440-498-3702

-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum Received on Wed Aug 26 1998 - 13:15:51 CDT

Original text of this message

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