假设如果我们在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)格式给出值。