MySQL convert column datatype from VARCHAR to INT

前端 未结 1 835
借酒劲吻你
借酒劲吻你 2021-02-18 20:01

I have a MySQL table with a VARCHAR(25) column that I want to convert to INT. All of the data in the column is either integer or blanks. I have tried this command:

<         


        
相关标签:
1条回答
  • 2021-02-18 20:31

    before altering your table, try to update your values.

    The goal is to set a '0' value in the fields where you have empty values (which can't be converted to int)

    update ip
    set isp = '0' where trim(coalesce(isp, '')) = '';
    

    If isp was not nullable, you can remove the coalesce function.

    update ip 
    set isp = '0' where trim(isp) = '';
    
    0 讨论(0)
提交回复
热议问题