
- 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
Which one is better in MySQL - NULL or empty string?
The choice depends upon the database. In ORACLE database, an empty string is converted to NULL.
In MySQL, the usage of an empty string is better as compared to NULL. It is easy to check for an empty string with some boundary conditions, while this cannot be done with NULL. To find NULL, we need to add an extra condition i.e. ‘IS NULL’
We can check that the length of NULL is 0 while length of empty string is 1.
To check the length of NULL.
mysql>SELECT count(NULL);
The following is the output of the above query.
+-----------------+ | count(NULL) | +-----------------+ | 0 | +-----------------+ 1 row in set (0.05 sec)
Therefore, the length of NULL is 0 in MySQL.
To check the length of an empty string.
mysql>SELECT count('');
The following is the output.
+-----------+ | count('') | +-----------+ | 1 | +-----------+ 1 row in set (0.00 sec)
It shows that the length of an empty string is 1.
- Related Articles
- Which one is better to insert NULL or empty string in MySQL?
- Which one is better POW() or POWER() in MySQL?
- How to test String is null or empty?
- Check if a String is empty ("") or null in Java
- Empty string in not-null column in MySQL?
- Check whether a field is empty or null in MySQL?
- Check if a String is whitespace, empty ("") or null in Java
- How to check if field is null or empty in MySQL?
- How to update empty string to NULL in MySQL?
- Java Program to Check if a String is Empty or Null
- Golang program to check if a string is empty or null
- Which one is better Build, Rebuild, or Clean in C#?
- Checking for Null or Empty or White Space Only String in Java.
- How it is possible to insert a zero or an empty string into a MySQL column which is defined as NOT NULL?
- Java program to find whether the given string is empty or null

Advertisements