How to handle null field when exporting MYSQL tables to CSV

前端 未结 4 1158
死守一世寂寞
死守一世寂寞 2021-02-18 21:36

Right now when I export MYSQL tables to CSV files, I\'m getting \\N for NULL fields in the database which is expected. If there a way to change the \\N output to just an empty s

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-18 22:02

    Just in case. To avoid typing "ifnull(var,'') as var" for every single variable one can use this:

    SELECT GROUP_CONCAT(CONCAT("IFNULL(",COLUMN_NAME,",'') AS ", COLUMN_NAME))
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = ''
    AND TABLE_SCHEMA = ''
    ORDER BY ORDINAL_POSITION
    
        

    提交回复
    热议问题