MySQL 5.7 STR_TO_DATE
MySQL 5.7 STR_TO_DATE
我是 运行 MySQL 5.7 并且想将一些字符串转换为日期。我在这里参考了手册:
http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_str-to-date
并尝试了以下(请注意 MySQL 版本)
mysql> SELECT STR_TO_DATE('9','%m');
+-----------------------+
| STR_TO_DATE('9','%m') |
+-----------------------+
| NULL |
+-----------------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+--------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------+
| Warning | 1411 | Incorrect datetime value: '9' for function str_to_date |
+---------+------+--------------------------------------------------------+
1 row in set (0.00 sec)
但是从 MySQL 5.7 的联机手册中,我应该看到以下内容:
mysql> SELECT STR_TO_DATE('9','%m');
-> '0000-09-00'
我是否遗漏了什么,或者这可能是一个错误?
正如手册中所说,
If the NO_ZERO_DATE or NO_ZERO_IN_DATE SQL mode is enabled, zero dates or part of dates are disallowed. In that case, STR_TO_DATE() returns NULL and generates a warning
在这种情况下,这会导致结果为 NULL,因为您的部分“日期”包含零值。
我是 运行 MySQL 5.7 并且想将一些字符串转换为日期。我在这里参考了手册: http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_str-to-date
并尝试了以下(请注意 MySQL 版本)
mysql> SELECT STR_TO_DATE('9','%m');
+-----------------------+
| STR_TO_DATE('9','%m') |
+-----------------------+
| NULL |
+-----------------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+--------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------+
| Warning | 1411 | Incorrect datetime value: '9' for function str_to_date |
+---------+------+--------------------------------------------------------+
1 row in set (0.00 sec)
但是从 MySQL 5.7 的联机手册中,我应该看到以下内容:
mysql> SELECT STR_TO_DATE('9','%m');
-> '0000-09-00'
我是否遗漏了什么,或者这可能是一个错误?
正如手册中所说,
If the NO_ZERO_DATE or NO_ZERO_IN_DATE SQL mode is enabled, zero dates or part of dates are disallowed. In that case, STR_TO_DATE() returns NULL and generates a warning
在这种情况下,这会导致结果为 NULL,因为您的部分“日期”包含零值。