Oracle implements a query like multiple values

Source: Internet
Author: User

Issue Background Description:

One day the customer has a demand, given a number of mobile phone numbers or phone numbers, to find out the relevant call records, as well as some related information.

Customer-given called number:

The results of the query are as shown (the results of this batch are not the results of the import query, in order to format the description, so import two images unrelated to the result):

Because the customer gave the called number is very irregular, query time is more troublesome.

Analysis Process:

I created a new table Security_phonebill_callee_num to hold the imported called number information.

All call data is saved in t_phonebill_201702, want to query must implement like, is the following SQL implementation effect

Select org_caller_num,org_callee_num,call_seconds,start_time,switch_id,
In_trunk,out_trunk,settle_carrier,file_name
From t_phonebill_201702 A
where a.org_callee_num like '%13800100186% '

But the number of such numbers are many, sometimes more than 100, the above SQL can only query a number of call records

At first I wanted to implement a cursor, write a cursor, put the called number into the cursor, and then write a loop, and each time it is queried in turn,

But later found that the t_phonebill_201702 data volume is too large, like a time to spend 20 minutes, 100 is 2000 minutes (30 hours), time consuming is too large, efficiency is too low.

Later access to information, several attempts to write down this SQL, finally is the implementation of the query, experimental argumentation efficiency is also good.

Select org_caller_num,a.org_callee_num,call_seconds,start_time,switch_id,
In_trunk,out_trunk,settle_carrier,file_name
From t_phonebill_201702 A
where exists
(select 1 from security_phonebill_callee_num C where a.org_callee_num
Like '%| |c.org_callee_num| |% ');

If the t_phonebill_201702 table has a small amount of data, consider using a simple version that is easier to understand and clearer about how the multiple values of like are implemented, but using exists is always a good habit. If you have similar needs, hope can help you.

Select org_caller_num,a.org_callee_num,call_seconds,start_time,switch_id,
In_trunk,out_trunk,settle_carrier,file_name
From t_phonebill_201702 A,security_phonebill_callee_num C
where A.org_callee_num like '%| |c.org_callee_num| |% '

Oracle implements a query like multiple values

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.