【发布时间】:2021-12-19 03:28:05
【问题描述】:
我有以下疑问 -
SELECT "Abc" AS result;
+--------+
| result |
+--------+
| Abc |
+--------+
SELECT TO_BASE64("Abc") AS result;
+--------+
| result |
+--------+
| QWJj |
+--------+
SELECT FROM_BASE64(TO_BASE64("Abc")) AS result;
+----------------+
| result |
+----------------+
| 0x416263 |
+----------------+
--binary-as-hex mysql 开发站点中的页面显示 -
要禁用十六进制表示法,请使用
--skip-binary-as-hex
我尝试了以下但得到错误 -
mysql> SELECT FROM_BASE64(TO_BASE64("Abc")) --skip-binary-as-hex AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as-hex AS result' at line 1
mysql> SELECT FROM_BASE64(TO_BASE64("Abc") --skip-binary-as-hex) AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as-hex) AS result' at line 1
mysql> SELECT FROM_BASE64(TO_BASE64("Abc" --skip-binary-as-hex)) AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as-hex)) AS result' at line 1
在同一页面中,他们说我如何使用USING utf8mb4 子句在CHAR() 和CONVERT() 函数的情况下获得结果,但他们没有说明FROM_BASE64() 函数的任何内容。不过,我试了一下,报错了——
SELECT FROM_BASE64(TO_BASE64("Abc") USING utf8mb4) AS result;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING utf8mb4) AS result' at line 1
我试过UNHEX()函数-
ELECT UNHEX(FROM_BASE64(TO_BASE64("Abc"))) AS result;
+----------------+
| result |
+----------------+
| 0x0ABC |
+----------------+
显然,这不是预期的结果,因为所有人都在大写。这里LCASE() 不能正常工作,因为它会将每个单词都变成小写。
甚至,从 -
可以看出,这个结果不是字符串SELECT SUBSTRING(UNHEX(FROM_BASE64(TO_BASE64("Abc"))) FROM 4) AS result;
+----------------+
| result |
+----------------+
| 0x |
+----------------+
所以唯一的选择似乎是禁用-binary-as-hex
但我找不到这样做的方法。
stackoverflow 中有类似的问题 -
'FROM_BASE64' Function Returns Hex Value
但它在 MySQL 版本 5.6.14 上。我正在使用 MySQL 版本 8.0.27 -
mysql --version
mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
所以我的情况不同。
【问题讨论】:
标签: mysql binary base64 hex string-function