将十六进制值插入mysql

发布于 2024-07-09 13:14:11 字数 132 浏览 4 评论 0原文

有什么方法可以将十六进制值插入MYSQL吗? 我还希望能够以十六进制形式检索它。

例如,类似: 插入表(十六进制标签) 值(十六进制(0x41));

如果我这样做,我希望它在表中添加一个“A”

Can there any way to insert a hex value into MYSQL?
I also want to be able to retreive it in hex form.

For example, something like:
INSERT INTO table ( hexTag )
VALUES ( HEX(0x41) );

And if I do this, I want it to put an 'A' into the table

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┾廆蒐ゝ 2024-07-16 13:14:11

对于该特定用例,您可以直接插入十六进制值,它将被解释为字符串,或者使用 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)

请参阅 这些 链接

For that particular use case, you can either insert the hex value directly and it will be interpreted as a string, or use HEX() to input and UNHEX() to output

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)

See these links.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文