关于LIKE语句之中使用子查询

0
因为LIKE语句的使用只能是返回值是单行,那再如果我希望返回值是多个呢,也就是说我希望LIKE 后面跟着是多个返回值,怎么解决
已邀请:
0

老头子 - 专注是唯一的捷径 2016-10-21 回答

with a as
(select 'aa' a,1 b from dual union all
select 'bb' a,2 b from dual union all
select 'dd' a,3 b from dual 
),
b as
(select 'a' a,1 b from dual union all
select 'b' a,2 b from dual union all
select 'c' a,3 b from dual )
select *
from a left join b on a.a like '%'||b.a||'%'
where b.a is not null
;
 
或者用exists
with a as
(select 'aa' a,1 b from dual union all
select 'bb' a,2 b from dual union all
select 'dd' a,3 b from dual 
),
b as
(select 'a' a,1 b from dual union all
select 'b' a,2 b from dual union all
select 'c' a,3 b from dual )
select *
from a a
where exists (select 1 from b b where a.a like '%'||b.a||'%')
;
 

要回复问题请先登录注册