MySQL在insert時遇到“Incorrect integer value: '' for column 'idx' at row 1“

 在之前一篇blog中有提到mysql常用數據庫語句時,使用過以下語句:

insert into new_table select NULL,a.phone,name,age,address,NULL, b.birth
from students a, info_table b 
where studentnum in (
    '20180722121735',
    '20180721174759',
    '20180720103621',
    '20180718122414'
  ) and a.phone= b.phone

前兩天用時還挺好,換了一臺mysql服務器後就突然報錯,錯誤信息是“Incorrect integer value: '' for column 'idx' at row 1”,萬能的www一搜發現是mysql服務器版本不一樣導致,mysql版本到5以上的就會這樣,插入空字符要使用NULL,因此正確的語句應該是:

insert into new_table select NULL,a.phone,name,age,address,NULL, b.birth
from students a, info_table b 
where studentnum in (
    '20180722121735',
    '20180721174759',
    '20180720103621',
    '20180718122414'
  ) and a.phone= b.phone

僅記之

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章