What happens when a SQL fuzzy query encounters a null value?

Source: Internet
Author: User

Iamlaosong

SQL query statement using% to do fuzzy query, the program generally requires users to enter some information, based on this information fuzzy query. For example, user input 340104, the following statement is to query yesterday customer code 340104 beginning with all the message information:

SELECT * from  tb_evt_mail_clct t where t.clct_date = Trunc (sysdate-1) and   t.sender_cust_code like ' 340,104% '

When the user does not enter anything need to query yesterday all the message information, the following statement does not query all information, this statement can only find all the big customer's mail information, unable to find retail e-mail information:

SELECT * from  tb_evt_mail_clct t where t.clct_date = Trunc (sysdate-1) and   t.sender_cust_code like '% '

This is because the retail customer code is NULL, and the following statement can take into account both of the above two scenarios (with 0000 for null values):

Has a limit value:

SELECT * from  tb_evt_mail_clct t where t.clct_date = trunc (sysdate-1)   and NVL (t.sender_cust_code, ' 0000 ') LIKE ' 3 40,104% '

Infinite value:

SELECT * from  tb_evt_mail_clct t where t.clct_date = trunc (sysdate-1)   and NVL (t.sender_cust_code, ' 0000 ') like '% '

The limit value is 0000 When the result is all retail:

SELECT * from  tb_evt_mail_clct t where t.clct_date = trunc (sysdate-1)   and NVL (t.sender_cust_code, ' 0000 ') like ' 0 0% '






What happens when a SQL fuzzy query encounters a null value?

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.