带有like子句的Oracle连接查询

带有like子句的Oracle连接查询,oracle,Oracle,我需要用两个表的组合获取结果 select template_id from templatetbl where template_xml like '%889d-5765405edb42%' 在查询中,我得到了24张记录 现在,我想获取另一组具有我之前获得的模板id的记录 select * from sites where site_xml like '%templateid%'. Templateid是我之前得到的 select * from sites where site

我需要用两个表的组合获取结果

select template_id 
from templatetbl 
where template_xml like '%889d-5765405edb42%'
在查询中,我得到了24张记录

现在,我想获取另一组具有我之前获得的模板id的记录

select * 
from sites 
where site_xml like '%templateid%'.
Templateid是我之前得到的

select * 
from sites 
where site_xml like '%templateid%'.
我试着这样问

select * 
from sites 
where site_xml like (select template_id 
                     from templatetbl 
                     where template_xml like '%889d-5765405edb42%')
但将错误获取为单行子查询将返回多行

请帮助合并这两个查询

尝试以下操作:

select * 
from sites 
where site_xml like (select '''%'||template_id||'%'''
                     from templatetbl 
                     where template_xml like '%889d-5765405edb42%')

这应该可以做到。一个简单的连接,在其中动态构建
LIKE
字符串

SELECT S.*
FROM   templatetbl T, sites S
WHERE  T.template_xml LIKE '%889d-5765405edb42%'
AND    S.site_xml     LIKE '%'||TO_CHAR(T.templateid)||'%'

编辑:不过要注意,这可能不是你想要的。因为
1
templateid
将匹配
1
10
11
<代码>21
100
etc

我认为如果子查询与
templatetbl上的多行匹配,则仍然会出现
行数过多的错误