将十六进制值插入 MySql
我有一个带有 VARBINARY 列的表.我需要插入一个字符串,例如4D2AFF",它分别代表十六进制值 0x4D、0x2A 和 0xFF.我如何构造这个语句?
I have a table with a VARBINARY column. I need to insert a string such as '4D2AFF' which represents the hex values 0x4D, 0x2A and 0xFF respectively. How do I construct this statement?
推荐答案
你可以使用UNHEX()
函数将具有十六进制对的十六进制字符串转换为二进制和 HEX()
反过来做.
You can use UNHEX()
function to convert a hexstring with hex pairs to binary and HEX()
to do the other way round.
即
INSERT INTO tbl (col) VALUES (UNHEX('4D2AFF'))
和
SELECT HEX(col) FROM tbl
相关文章