MySQL judges null and empty string

Source: Internet
Author: User

1. Null in MySQL cannot be used with any operator with other fields or variables (functions, stored procedures). There may be a problem if you use arithmetic data.

2. The judgment of NULL:

Create a user table: ID Key name can be empty

select * from user;

Insert into user values (' + ', null); # #创建一条name为空的数据

Insert into user values (' 222 ', '); # #创建一条为空字符的数据

  

Use ISNULL to determine if null: Only name is null when the return value of the ISNULL (exp) function is 1, the empty string and the data are 0;

The SQL statement filtered to NULL can also be used with the SELECT * from user, where name is not null;

or select * from user where ISNULL (name) = 0;

3. Simultaneous culling of null and empty strings

SELECT * from user where ISNULL (name) =0 and LENGTH (Trim (name)) >0;

4 determining whether null or an empty string in a function or stored procedure

SELECT Id,name,casewhen (ISNULL (name) =1) | | (LENGTH (Trim (NAME)) =0) Then  ' AAA ' Endfromuser

 

MySQL judges null and empty string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.