简体   繁体   English

Oracle SQL喜欢从其他表中选择的多个条件

[英]Oracle sql like multiple conditions with select from other table

I have 375 dialcodes in table "temp": 我在表“ temp”中有375个拨号代码:

917277
917278
918083
...
9172738

I can do the following: 我可以执行以下操作:

select * from cdr where 
dnis like 917277% or
dnis like 917278% or
dnis like 918083% or
...
dnis like 9172738%

Is it possible to make a query including "select in" and "like %" conditions? 是否可以进行包含“选择入”和“类似%”条件的查询?

select * from cdr where dnis in (select dialcode% from temp)

You can use JOIN and LIKE to achieve similiar result: 您可以使用JOINLIKE达到相似的结果:

SELECT c.*           -- DISTINCT may be needed if dialcodes overlap each other
FROM cdr c
JOIN temp t
  ON c.dnis LIKE t.dialcode || '%'

One method is to use exists : 一种方法是使用exists

select c.*
from cdr c
where exists (select 1 from temp t where c.dnis like dialcode || '%' );

Note that this does not require distinct , even when there might be multiple matches. 请注意,即使可能存在多个匹配项,也不需要distinct

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM