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