英语不是我的母语;请原谅输入错误。
我使用5.5.38-MariaDB。 mysql语句:
SELECT CAST(11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
AS char);
我得到的结果是99999999999999999999999999999999999999999999999999999999999999999
,为什么?
更新:
MariaDB [(none)]> SELECT CAST(199999999999999999999999999999999999999999999999999999999999999999999999999999999 AS char);
+-------------------------------------------------------------------------------------------------+
| CAST(199999999999999999999999999999999999999999999999999999999999999999999999999999999 AS char) |
+-------------------------------------------------------------------------------------------------+
| 199999999999999999999999999999999999999999999999999999999999999999999999999999999 |
+-------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> SELECT CAST(1999999999999999999999999999999999999999999999999999999999999999999999999999999999 AS char);
+--------------------------------------------------------------------------------------------------+
| CAST(1999999999999999999999999999999999999999999999999999999999999999999999999999999999 AS char) |
+--------------------------------------------------------------------------------------------------+
| 99999999999999999999999999999999999999999999999999999999999999999 |
+--------------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.01 sec)
MariaDB [(none)]> SHOW WARNINGS;
+---------+------+--------------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------------+
| Warning | 1916 | Got overflow when converting '' to DECIMAL. Value truncated. |
+---------+------+--------------------------------------------------------------+
1 row in set (0.00 sec)
答案 0 :(得分:1)
1111...
被解析为数字,尤其是DECIMAL(65, ...)
。最大为65;因为东西比那还大,所以给了您65个9。它给了你一个警告(可能被忽略了):
mysql> SELECT CAST(11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 AS CHAR) AS too_big;
+-------------------------------------------------------------------+
| too_big |
+-------------------------------------------------------------------+
| 99999999999999999999999999999999999999999999999999999999999999999 |
+-------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;
+---------+------+---------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DECIMAL value: '' |
+---------+------+---------------------------------------+
1 row in set (0.00 sec)
您希望得到什么?