varbinary - Working with Binary Data in MySQL -
select 0x0000987c col1, substr(binarydata,1,4) col2, cast(0x0000987c signed) col3, cast(substr(binarydata,1,4) signed) col4 ( select 0x0000987c00000000 binarydata ) d
returns
col1 col2 col3 col4 ---- ---- ----- ---- blob blob 39036 0
when @ blob viewer col1
, col2
both appear identical (screenshot below).
so why different results col3 , col4?
i think has data types. binarydata has integer data type, substr(binarydata,1,4) expects string. cast gets confused result. also, cast parses strings using base 10, need little bit of work. try this:
cast(conv(substr(hex(binarydata),1,8), 16, 10) signed) col4
it's monster, should give want.
Comments
Post a Comment