Home > Database > Mysql Tutorial > 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
Release: 2023-08-23 20:09:12
forward
822 people have browsed it

如果我们从包含 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)
Copy after login

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)
Copy after login

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
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template