此類計算可能會導致不可預測的結果,因為當日期表示為 MySQL 字符串時,MySQL 會嘗試僅采用第一個出現(xiàn)的字符串來對字符串執(zhí)行數(shù)字運算。以下示例將闡明它 –
mysql> select '2017-10-17' + 20; +-------------------+ | '2017-10-17' + 20 | +-------------------+ | 2037 | +-------------------+ 1 row in set, 1 warning (0.00 sec) mysql> select '2017-10-25' - 17; +-------------------+ | '2017-10-25' - 17 | +-------------------+ | 2000 | +-------------------+ 1 row in set, 1 warning (0.00 sec) mysql> select '2017-10-17' * 2; +-------------------+ | '2017-10-17' * 20 | +-------------------+ | 4034 | +-------------------+ 1 row in set, 1 warning (0.00 sec) mysql> select '2017-05-25'/5; +----------------+ | '2017-05-25'/5 | +----------------+ | 403.4 | +----------------+ 1 row in set, 1 warning (0.00 sec)
登錄后復制
以上就是加法、減法、乘法和除法運算符如何處理表示為 MySQL 字符串的日期?的詳細內容,更多請關注www.92cms.cn其它相關文章!