如果从包含NULL值的表中将数据导出到CSV文件,我们如何在CSV文件中存储\ N以外的其他值?
如果要在从包含NULL值的表中将数据导出到CSV文件时,在CSV文件中存储\N以外的任何其他值,则需要使用IFNULL语句将\N值替换为其他值。为了说明这一点,我们采用以下示例-
例
假设我们要导出具有以下数据的表'student_info'的值-
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | | 150 | Saurabh | NULL | Literature | +------+---------+------------+------------+ 7 rows in set (0.00 sec)
如我们所见,结果的id为150的地址字段的结果为NULL。现在,以下查询将将该表的数据导出到Student_28.CSV并在\N位置存储“不适用”-
mysql> Select IFNULL(id,'Not Applicable'), IFNULL(Name,'Not Applicable'), IFNULL(Address,'Not Applicable'), IFNULL(Subject,'Not Applicable') from Student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student_28.csv' FIELDS TERMINATED BY ',';
从以下值可以看出,student_28.CSV在\N处不适用-
101 YashPal Amritsar History 105 Gaurav Chandigarh Literature 125 Raman Shimla Computers 130 Ram Jhansi Computers 132 Shyam Chandigarh Economics 133 Mohan Delhi Computers 150 Saurabh Not Applicable Literature
热门推荐
10 万寿祝福语简短
11 周末祝福语简短的英语
12 爱情贺卡祝福语简短英语
13 简短霸气的考试祝福语
14 老人过大寿祝福语简短
15 生日祝福语 简短独特高考
16 祝福语写给自己的简短
17 端午老师祝福语简短优美
18 下雨开工吉祥祝福语简短