mariadb mysql中的X'val'表示法似乎总是计算为零,并抱怨该值不正确

b0zn9rqh  于 2022-12-04  发布在  Mysql
关注(0)|答案(1)|浏览(111)

我确信我在这里忽略了一些简单而明显的东西...我从MySQL 8.0手册的十六进制文字页面复制了这个示例(在这里:(第10页)
具体来说,手册在页面的中间给出了以下示例:

mysql> SET @v1 = X'41';
mysql> SET @v2 = X'41'+0;
mysql> SET @v3 = CAST(X'41' AS UNSIGNED);
mysql> SELECT @v1, @v2, @v3;
+------+------+------+
| @v1  | @v2  | @v3  |
+------+------+------+
| A    |   65 |   65 |
+------+------+------+

然而,当我逐字使用这个例子时,我得到了下面的输出(我打开了警告,这样您就可以看到发生了什么):

MariaDB> \W
Show warnings enabled.
MariaDB> SET @v1 = X'41';
Query OK, 0 rows affected (0.00 sec)

MariaDB> SET @v2 = X'41'+0;
Query OK, 0 rows affected, 1 warning (0.00 sec)

Warning (Code 1292): Truncated incorrect DOUBLE value: 'A'
MariaDB> SET @v3=CAST(X'41' AS UNSIGNED);
Query OK, 0 rows affected, 1 warning (0.00 sec)

Warning (Code 1292): Truncated incorrect INTEGER value: 'A'
MariaDB> SELECT @v1, @v2, @v3;
+------+------+------+
| @v1  | @v2  | @v3  |
+------+------+------+
| A    |    0 |    0 |
+------+------+------+
1 row in set (0.00 sec)

如果它能帮助您了解我的设置中可能存在的错误:

MariaDB> SELECT @@character_set_database, @@collation_database;
+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8mb4                  | utf8mb4_general_ci   |
+--------------------------+----------------------+
1 row in set (0.00 sec)

很明显,我不满意,我想我应该做的事情我还没有做,但我不知道是什么。
我正在使用:mysql Ver 15.1 Distrib 10.1.48-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
编辑:(更多信息)。我想知道问题是否与MariaDB客户端有关,但当我从PHP调用MySQL时,问题仍然存在。示例:

\core\report($this->query("SELECT X'41'+0")->toArray()); //report() and toArray() are my own functions.

在日志文件中生成以下输出:

object(stdClass)#23 (1) {
    ["X'41'+0"]=>
    string(1) "0"                     <--- Still 0
}
hxzsmxv2

hxzsmxv21#

MariaDB不是MySQL,所以你必须查看MariaDB的手册。请参阅十六进制文字一章,特别是MariaDB和MySQL之间的差异一章,其中定义了这种行为:

MariaDB和MySQL之间的差异

SELECT x'0a'+0;
+---------+
| x'0a'+0 |
+---------+
|       0 |
+---------+
1 row in set, 1 warning (0.00 sec)

Warning (Code 1292): Truncated incorrect DOUBLE value: '\x0A'

SELECT X'0a'+0;
+---------+
| X'0a'+0 |
+---------+
|       0 |
+---------+
1 row in set, 1 warning (0.00 sec)

Warning (Code 1292): Truncated incorrect DOUBLE value: '\x0A'

SELECT 0x0a+0;
+--------+
| 0x0a+0 |
+--------+
|     10 |
+--------+

在MySQL中(最低版本为MySQL 8.0.26):

SELECT x'0a'+0;
+---------+
| x'0a'+0 |
+---------+
|      10 |
+---------+

SELECT X'0a'+0;
+---------+
| X'0a'+0 |
+---------+
|      10 |
+---------+

SELECT 0x0a+0;
+--------+
| 0x0a+0 |
+--------+
|     10 |
+--------+

相关问题