首頁  >  文章  >  資料庫  >  我們如何在 MySQL 中提供只有年(零個月和零天)值的日期?

我們如何在 MySQL 中提供只有年(零個月和零天)值的日期?

王林
王林轉載
2023-09-03 08:53:02913瀏覽

我们如何在 MySQL 中提供只有年(零个月和零天)值的日期?

透過停用 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)

以上是我們如何在 MySQL 中提供只有年(零個月和零天)值的日期?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除