In the MySQL database, null is a common situation. What are the precautions regarding null in MySQL? The following is a brief summary, which will be supplemented later. 1. is null First, determine whether the value of a column in the database is null. You cannot use equals to determine whether it is null. You must use is. For example, select * from users where user_name is null or select * from users where user_name is not null, but not select * from users where user_name = null 2. ISNULL() The ISNULL() function is built into the MySQL database and its usage is the same as other built-in functions such as sum() provided in MySQL. For example, select ISNULL(user_name) from users where user_name = 'Demrystv' returns 0; select ISNULL(NULL) returns 1 3. IFNULL() The MySQL database has a built-in IFNULL() function, and its usage is the same as other built-in functions such as sum() provided in MySQL. It mainly receives two parameters. The first parameter is the field or value to be judged as null, and the second field is another value to be returned when the first parameter is null. That is, if the first field is null, it will be replaced with another value. For example, select IFNULL(NULL, "java is the best language of the world"), since the value of the first parameter is NULL, the value of the second parameter, java is the best language of the world, will be output; similarly, if the first field is not empty, the value of the first field will be returned. 4. insert into and null When using insert into to fill data into a table, you need to first make sure whether the table is null or empty. If it is null, you cannot use insert into to fill data, and you must use update. This seems simple, but it is often overlooked in actual development, so special attention needs to be paid. example: Create a test table, colA cannot store null values, but colB can store null values. CREATE TABLE `test` ( `colA` varchar(255) NOT NULL, `colB` varchar(255) DEFAULT NULL )ENGINE=InnoDB DEFAULT CHARSET=utf8; The above are all the relevant knowledge points introduced this time. Thank you for your learning and support for 123WORDPRESS.COM. You may also be interested in:
|
<<: Tutorial on building svn server with docker
>>: js realizes horizontal and vertical sliders
In the previous chapters, we introduced how to ch...
Today I was browsing the blog site - shoptalkshow...
Simply put, src means "I want to load this r...
The computer system has been reinstalled, and the...
1. Add a new user Only allow local IP access crea...
1) Introduction to cache mechanism In the Linux s...
Step 1: Configure environment variables (my decom...
Previously, I summarized how to use CSS to achieve...
Table of contents background: Nginx smooth upgrad...
Share a real-time clock effect implemented with n...
Scenario You need to authorize the tester to use ...
I wonder if you are like me, a programmer who arr...
Table of contents design Component Communication ...
Tutorial Series MySQL series: Basic concepts of M...
Table of contents 1. Implementation Background 2....