假设如果我们在 mysql 表中存储了一个日期值“0000-00-00”,那么从此类日期中提取年份值时,mysql 将返回 0。它不会位于 year(2) 或 year 中(4)格式。为了理解它,我们使用“detail_bday”表中的以下数据 -
mysql> select * from detail_bday;+----+---------+------------+| sr | name | birth_date |+----+---------+------------+| 1 | saurabh | 1990-05-12 || 2 | raman | 1993-06-11 || 3 | gaurav | 1984-01-17 || 4 | rahul | 1993-06-11 || 5 | sonia | 1993-11-31 || 6 | ram | 0000-00-00 |+----+---------+------------+6 rows in set (0.00 sec)
现在以下查询将尝试从日期“0000-00-00”获取年份值 -
mysql> select year(birth_date) from detail_bday where name = 'ram';+------------------+| year(birth_date) |+------------------+| 0 |+------------------+1 row in set (0.00 sec)
上面的结果集显示 mysql 返回 0,而不是按照 year(2) 或 year(4) 格式给出值。
以上就是mysql将以哪种格式year(2)或year(4)返回从日期“0000-00-00”开始的年份值?的详细内容。