Test code for NULL values in SQL

Source: Internet
Author: User

You just want to retrieve the records whose Modifier (type VARCHAR2 (20) can be empty) is null from the database table EXPERT_DETAILS, because the field type is VARCHAR2 (20 ), the SQL statement I use is
Copy codeThe Code is as follows:
Select * from expert_details twhere t. modifier =''

No record is retrieved, which is inconsistent with the records stored in the table. Later I thought that even the empty volume storage should be NULL rather than ''in the database ''.

Then I used the following SQL statement and still did not retrieve a record.
Copy codeThe Code is as follows:
Select * from expert_details t
Where t. modifier = null

Finally, I thought of testing the NULL value in SQL. Use the following statement to finally retrieve the desired result.
Copy codeThe Code is as follows:
Select * from expert_details t
Where t. modifier is null

In SQL statements, where clause: where t. modifier = null. The NULL keyword cannot be used here because it is not a real value. It is just a symbol because its value is unknown. When t. when modifier itself is null, that is, the where clause is: where null = null. When the values on both sides of the equal sign are unknown, the result is TRUE or FALSE. SQL cannot provide a clear result, therefore, the query result is NULL.

Therefore, the NULL value test must be explicitly used, that IS, the field is null or its negative form field is not null, to detect the NULL value.

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.