国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL中日期比較時遇到的編碼問題解決辦法

2024-07-24 12:47:01
字體:
來源:轉載
供稿:網友

今天幫同事處理一個SQL(簡化過后的)執行報錯:

復制代碼 代碼如下:

mysql> select date_format('2013-11-19','Y-m-d') > timediff('2013-11-19', '2013-11-20');                                        

ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,NUMERIC) for operation '>'


乍一看挺莫名其妙的,查了下手冊,發現有這么一段:
復制代碼 代碼如下:

The language used for day and month names and abbreviations is controlled by the value of the lc_time_names system variable (Section 9.7, “MySQL Server Locale Support”).

The DATE_FORMAT() returns a string with a character set and collation given by character_set_connection and collation_connection so that it can return month and weekday names containing non-ASCII characters.


也就是說,DATE_FORMATE() 函數返回的結果是帶有字符集/校驗集屬性的,而 TIMEDIFF() 函數則沒有字符集/校驗集屬性,我們來驗證一下:
復制代碼 代碼如下:

mysql> set names utf8;
mysql> select charset(date_format('2013-11-19','Y-m-d')), charset(timediff('2013-11-19', '2013-11-20'));
+--------------------------------------------+-----------------------------------------------+
| charset(date_format('2013-11-19','Y-m-d')) | charset(timediff('2013-11-19', '2013-11-20')) |
+--------------------------------------------+-----------------------------------------------+
| utf8                                       | binary                                        |
+--------------------------------------------+-----------------------------------------------+

mysql> set names gb2312;
mysql> select charset(date_format('2013-11-19','Y-m-d')), charset(timediff('2013-11-19', '2013-11-20'));
+--------------------------------------------+-----------------------------------------------+
| charset(date_format('2013-11-19','Y-m-d')) | charset(timediff('2013-11-19', '2013-11-20')) |
+--------------------------------------------+-----------------------------------------------+
| gb2312                                     | binary                                        |
+--------------------------------------------+-----------------------------------------------+

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高淳县| 交城县| 江华| 通辽市| 五常市| 太湖县| 绵竹市| 黑水县| 酉阳| 沿河| 若尔盖县| 历史| 荣昌县| 滨州市| 镇安县| 莱州市| 秦皇岛市| 渭源县| 普兰店市| 绿春县| 永和县| 灵宝市| 兴城市| 左权县| 浮梁县| 松滋市| 大同市| 玉龙| 兴义市| 岑溪市| 昌邑市| 虎林市| 司法| 海盐县| 洪湖市| 石屏县| 锡林浩特市| 寿宁县| 天长市| 鄂托克旗| 阿鲁科尔沁旗|