oracle =多个值,Oracle实现like多个值的查询

我新建了一个表security_phonebill_callee_num,用以存放导入的被叫号码信息

所有的通话数据保存在t_phonebill_201702中,想要查询必须要实现like,就是以下sql的实现效果

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%'

但是这样的号码有好多个,有时候有一百多个,以上的sql只能查询一个号码的通话记录

一开始我想用游标实现,写一个游标,把被叫号码放入游标中,然后写一个循环,每次都依次查询一下,

但后来发现t_phonebill_201702数据量太大,like一次就要花费时间20分钟,100个就是2000分钟(30个小时),耗时量太大,效率太低。

后来查阅资料,多次尝试下写下这个sql,总算是实现了查询,实验论证效率也还不错。

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||%') ;

如果t_phonebill_201702表的数据量不大,可以考虑使用简版,简版更易于了解,也能更清楚明白like多个值是如何实现的,但使用exists总是一个好习惯。如果你有类似的需求,希望可以帮到你。

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||%'