Subject Re: ASCII_VAL for BLOB
Author rj1102
I found out that typecasting as a text blob was the solution:

ASCII_VAL(CAST(SUBSTRING(Image FROM 1 FOR 1) AS BLOB SUB_TYPE TEXT))

Note typecasting as (VAR)CHAR(1) or CHAR(1) CHARACTER SET ASCII does *not* work.

According to the Firebird documentation, ASCII_VAL is only supported for (VAR)CHAR and text blobs, still i think it is better that also the right value should be returned for a byte in a binary blob, or that a 'not supported' error is raised.

Kind regards!


--- In firebird-support@yahoogroups.com, "rj1102" wrote:
>
> Using Firebird 2.5 (WI-V2.5.2.26539),
> I try to access a blob with jpeg image, but somehow not all bytes return the right ascii value.
>
> E.g. I know the first byte of the blob is x'FF' since statement below returns 'TRUE':
>
> SELECT IIF(SUBSTRING(Image FROM 1 FOR 1) = x'FF', 'TRUE', 'FALSE')
> FROM MyTable WHERE Id = 1
>
> However statement below returns 74 where I expect 255:
>
> SELECT ASCII_VAL(CAST(SUBSTRING(Image FROM 1 FOR 1) AS BLOB))
> FROM MyTable WHERE Id = 1
>
> Field Image is defined as BLOB(80, 0)
>
> Is there another reliable way to retrieve the numeric value of a byte inside a blob?
>
> Thank you very much in advance!
>
> Robert
>