gpt4 book ai didi

mysql - 将 MYSQL 表导出为 CSV 时如何处理空字段

转载 作者:IT老高 更新时间:2023-10-29 00:12:01 27 4
gpt4 key购买 nike

现在,当我将 MYSQL 表导出到 CSV 文件时,我得到\N 表示数据库中的 NULL 字段,这是预期的。将表导出到 csv 时,是否有办法将\N 输出更改为空字符串?

谢谢

SELECT 'CU_CustomerID','CU_UserName','CU_Password','CU_Email','CU_Company','CU_Comment','CU_LastBasket','CON_FirstName','CON_MiddleI','CON_LastName','CON_Address1','CON_Address2','CON_City','CON_State','CON_Province','CON_Country','CON_Zip','CON_Phone1','CON_Phone2'
UNION
SELECT T1.CU_CustomerID,T1.CU_UserName,T1.CU_Password,T1.CU_Email,T1.CU_Company,T1.CU_Comment,T1.CU_ShopperPoints,T2.CON_FirstName,T2.CON_MiddleI,T2.CON_LastName,T2.CON_Address1,T2.CON_Address2,T2.CON_City,T2.CON_State,T2.CON_Province,T2.CON_Country,T2.CON_Zip,T2.CON_Phone1,T2.CON_Phone2
FROM CUSTOMERS AS T1
INNER JOIN CONTACT AS T2 ON T1.CU_CustomerID = T2.CON_CustomerID
WHERE T1.CU_CustomerID BETWEEN 0 AND 1000
INTO OUTFILE 'customers.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'

最佳答案

来自 MySQL documentation

If the FIELDS ESCAPED BY character is empty, no characters are escaped and NULL is output as NULL, not \N. It is probably not a good idea to specify an empty escape character, particularly if field values in your data contain any of the characters in the list just given.

关于mysql - 将 MYSQL 表导出为 CSV 时如何处理空字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24250579/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com