技术文章和资源

技术文章(时间排序)

热门类别

Python PHP MySQL JDBC Linux

如何在 MySQL 中提供仅包含年份(零月份和零天)值的日期?

mysqlmysqli database

通过禁用 NO_ZERO_IN_DATE 模式,我们可以在 MySQL 表中存储仅包含年份值且包含零月份和零天值的日期。如果启用此模式,则 MySQL 会将此类日期视为无效日期并存储所有零。

mysql> Insert into year_testing (OrderDate) values('2017:00:00');
Query OK, 1 row affected (0.09 sec)

mysql> select * from year_testing;
+------------+
| OrderDate  |
+------------+
| 2017-00-00 |
+------------+
1 row in set (0.00 sec)

mysql> SET sql_mode = 'NO_ZERO_IN_DATE';
Query OK, 0 rows affected (0.00 sec)

mysql> Insert into year_testing(OrderDate) values('2017:00:00');
Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> Select * year_testing;
+------------+
| OrderDate  |
+------------+
| 2017-00-00 |
| 0000-00-00 |
+------------+
1 rows in set (0.00 sec)

相关文章