Home  >  Article  >  Database  >  How does MySQL evaluate if we export data to a CSV file from a table that contains NULL values?

How does MySQL evaluate if we export data to a CSV file from a table that contains NULL values?

WBOY
WBOYforward
2023-08-23 20:09:12741browse

如果我们从包含 NULL 值的表中将数据导出到 CSV 文件,MySQL 如何评估?

If we export data from a table that contains NULL values, then MySQL will store \N in the CSV file for the records with NULL values. It can be illustrated by the following example:

Example

Suppose we want to export the values ​​of the table 'student_info', which has the following data:

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)

We can see in the results The address field with id 150 has a NULL value. Now the following query will export the data of this table to Student_27.CSV -

mysql> Select * from Student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student_27.csv' FIELDS TERMINATED BY ',';
Query OK, 7 rows affected (0.02 sec)

The above query has stored the following values ​​in the file Student_27.CSV−

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   \N           Literature

We can see that MySQL has the following values ​​in the table Store \N where there are NULL values.

The above is the detailed content of How does MySQL evaluate if we export data to a CSV file from a table that contains NULL values?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete