You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by John English <jo...@gmail.com> on 2023/09/24 16:05:07 UTC

Writing hex integer constants?

Is there a way to use hex constants as integers in Derby?

I tried using X'7FFF' and I got "Comparisons between 'SMALLINT' and 
'CHAR () FOR BIT DATA' are not supported".
I tried using CAST(X'7FFF' AS INTEGER) and got "Cannot convert types 
CHAR () FOR BIT DATA to INTEGER".

I can of course use 32767 in this case, but for other hex values it's a 
real pain to work out what it corresponds to. Or I could define a 
function to convert a string hex value to an integer, but that also 
seems like overkill.

Thanks,
-- 
John English

Re: Writing hex integer constants?

Posted by Rick Hillegas <ri...@gmail.com>.
Derby INTEGER constants are signed decimal numbers, that is, legal 
inputs to the java.lang.Integer.valueOf(String s) method. The radix is 
always 10. Hex/octal constants won't work, as you've discovered.

On 9/24/23 9:05 AM, John English wrote:
> Is there a way to use hex constants as integers in Derby?
>
> I tried using X'7FFF' and I got "Comparisons between 'SMALLINT' and 
> 'CHAR () FOR BIT DATA' are not supported".
> I tried using CAST(X'7FFF' AS INTEGER) and got "Cannot convert types 
> CHAR () FOR BIT DATA to INTEGER".
>
> I can of course use 32767 in this case, but for other hex values it's 
> a real pain to work out what it corresponds to. Or I could define a 
> function to convert a string hex value to an integer, but that also 
> seems like overkill.
>
> Thanks,