Major problems caused by Oracle's or operator

Source: Internet
Author: User

During work, I found that a data computing result was abnormal. I checked the original data and did not find any problems. I then compared it with the system computing result. I was shocked: It was a lot bigger, so, check the program and find the following calls:

 

SelectTT. bc1610
FromTj_v_pfi_bc1610_bc1620 TT
 WhereTo_char (TT. tj_date, 'yyyymmm ') = '2016'
AndTT. regionid = 999.
OrTT. regionidIn(SelectB. regionid
FromTj_performance_region_sub B
WhereB.Type= 0
AndB. parentregionid = 999)

 

The result is indeed abnormal When execution is taken out. The check and analysis result shows that it is actually a problem with the where condition. The OR operator is used in the condition. Due to carelessness, they are not noticed, the result exception is changed to the SQL statement shown below, and the test is normal:

 

SelectNvl (Sum(Tt. bc1610), 0)
FromTj_v_pfi_bc1610_bc1620 TT
 WhereTo_char (TT. tj_date, 'yyyymmm ') = '2016'
And(Tt. regionid = 999
OrTT. regionidIn(SelectB. regionid
FromTj_performance_region_sub B
WhereB.Type= 0
AndB. parentregionid = 999 ));

 

The only difference is that the first sentence does not include the two or conditions.

 

At work, there are many places where or is used. If or is in parallel with other conditions, you must pay attention to the application of or.

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.