
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How MySQL evaluates if we export the data to CSV file from a table which contains a NULL value(s)?
If we export the data from a table having NULL values then MySQL will store \N in CSV file for the record MySQL table having NULL values. It can be illustrated with the help of the following example −
Example
Suppose if we want to export the values of the table ‘student_info’ having 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)
As we can see that the result has a NULL value for the address field where id is 150. Now the following query will export this table’s data into 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 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 stores \N where the table has a NULL value(s).
- Related Articles
- How can we store any other value than N in CSV file if we export the data to CSV file from a table which contains a NULL value(s)?
- How can we export all the data from MySQL table into a CSV file?
- How can we export some field(s) from MySQL table into a CSV file?
- How can we export data to a CSV file whose filename name contains timestamp at which the file is created?
- How can we export all the data from MySQL table into a text file?
- How can we export some field(s) from MySQL table into a text file?
- How can we import data from .CSV file into MySQL table?
- Python Tkinter – How to export data from Entry Fields to a CSV file?
- How MySQL stored function evaluates if it got NULL value while using the dynamic values from a table?
- How MySQL evaluates if we use any other escape character rather that back-slash () in a text file while importing the data from text file to MySQL table?
- How can we export data to a CSV file along with columns heading as its first line?
- What kind of settings can we do to a CSV file by query while exporting the values from MySQL table into a CSV file?
- How MySQL evaluates if we use EXISTS operator with the subquery that returns NULL?
- How can we import data from .txt file into MySQL table?
- How to read the data from a CSV file in Java?\n

Advertisements