在 MYSQL 中,我们如何存储日、月或月日都为零的日期?\日为零?
mysqlmysqli database更新于 2025/3/31 3:24:17
要存储日、月或月日都为零的此类日期,我们必须将 SQL 模式设置为 allow_invalid_dates 模式。
mysql> set sql_mode = 'allow_invalid_dates';
Query OK, 0 rows affected (0.00 sec)
mysql> insert into check_date(OrderDate) values('2017-00-00');
Query OK, 1 row affected (0.06 sec)
mysql> select * from check_date;
+-------------+
| OrderDate |
+-------------+
| 2017-00-00 |
+-------------+
1 row in set (0.00 sec)
上述查询将插入月份和日期值都为零的日期。
mysql> insert into check_date(Orderdate) values ('2017-00-05');
Query OK, 1 row affected (0.07 sec)
mysql> select * from check_date;
+------------+
| Orderdate |
+------------+
| 2017-00-00 |
| 2017-00-05 |
+------------+
2 rows in set (0.00 sec)
上述查询将插入月份值为零的日期。
mysql> insert into check_date(Orderdate) values ('2017-05-00');
Query OK, 1 row affected (0.02 sec)
mysql> select * from check_date;
+------------+
| Orderdate |
+------------+
| 2017-00-00 |
| 2017-00-05 |
| 2017-05-00 |
+------------+
3 rows in set (0.00 sec)
上述查询将插入日期值为零的日期。
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

