将十六进制值插入mysql

时间:2008-11-14 20:29:59

标签: mysql hex

有没有办法在MYSQL中插入十六进制值? 我也希望能够以十六进制形式进行检索。

例如,类似于: INSERT INTO表(hexTag) 价值(十六进制(0x41));

如果我这样做,我希望它将“A”放入表中

1 个答案:

答案 0 :(得分:4)

对于该特定用例,您可以直接插入十六进制值,它将被解释为字符串,或使用HEX()输入和UNHEX()输出

mysql> create table hexTable(pseudoHex varchar(50));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into hexTable values (0x41);
Query OK, 1 row affected (0.00 sec)

mysql> select * from hexTable;
+-----------+
| pseudoHex |
+-----------+
| A         |
+-----------+
1 row in set (0.00 sec)

mysql> select HEX(pseudoHex) from hexTable;
+----------------+
| HEX(pseudoHex) |
+----------------+
| 41             |
+----------------+
1 row in set (0.00 sec)

mysql> delete from hexTable;
Query OK, 1 row affected (0.00 sec)

mysql> insert into hexTable values (HEX('A'));
Query OK, 1 row affected (0.00 sec)

mysql> select UNHEX(pseudoHex) from hexTable;
+------------------+
| UNHEX(pseudoHex) |
+------------------+
| A                |
+------------------+
1 row in set (0.00 sec)

mysql> select * from hexTable;
+-----------+
| pseudoHex |
+-----------+
| 41        |
+-----------+
1 row in set (0.00 sec)

请参阅these links