All Forums General
felipe.donatti 4 posts Joined 09/14
17 Sep 2014
Convert to Hex

Hi,

I am new to the forum and topic teradata generally esou trying to do a conversion of a varchar column to hex, but I'm not getting a satisfactory result. In Oracle to convert a hex to varchar (select to_char ('141865918893551308', 'fmXXXXXXXXXXXXXXXXX')) I get the result '01F8024D35626ECC', which is correct, but in teradata to perform this conversion (SELECT CHAR2HEXINT ('141865918893551308')) the result is another '00310034003100380036003500390031003800380039003300350 0350031003300300038' how can I get the result '01F8024D35626ECC' ?

Tags:
dnoeth 4628 posts Joined 11/04
17 Sep 2014

Your example will not work as-is in Oracle.
What is the datatype of your input, VarChar, VarByte or any INT?
And what do you want as output, VarChar or VarByte?
 
In TD14 you might utilize TO_BYTES/FROM_BYTES.

Dieter

felipe.donatti 4 posts Joined 09/14
17 Sep 2014

Hello Dieter, thanks for the feedback,

My example would be a VARCHAR2 in Oracle (select to_char ('141865918893551308', 'fmXXXXXXXXXXXXXXXXXXX') from dual), this example works perfectly on Oracle. The return would be a varchar.
Would have an equivalent example in Teradata?

dnoeth 4628 posts Joined 11/04
17 Sep 2014

I didn't know you can apply TO_CHAR to a CHAR :)
Hopefully you're on TD14, TO_BYTES returns BYTE which can be used as input to FROM_BYTES to get a VARCHAR again:

SELECT FROM_BYTES(TO_BYTES ('141865918893551308', 'base10'), 'base16')

 
 

Dieter

felipe.donatti 4 posts Joined 09/14
17 Sep 2014

My version is 13.10.05.04. Is there another way?
 
Tks,

felipe.donatti 4 posts Joined 09/14
17 Sep 2014

RELEASE    13.10.05.03
LANGUAGE SUPPORT MODE    Standard
VERSION    13.10.05.04

dnoeth 4628 posts Joined 11/04
19 Sep 2014

There's no built-in way to cast from/to bytes besides those new functions in TD14.
You need to write a C-UDF.

Dieter

You must sign in to leave a comment.