2013-05-30 22 views
2

我需要獲取結果與兩個表的組合。甲骨文加入查詢與類似的條款

select template_id 
from templatetbl 
where template_xml like '%889d-5765405edb42%' 

在quering上,我得到了24條記錄。

現在我想用我之前得到的模板ID獲取另一組記錄。

select * 
from sites 
where site_xml like '%templateid%'. 

Templateid是我之前得到的。

我想這樣的查詢

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

但得到錯誤的單行子查詢返回多行。

請幫到這兩個查詢

回答

1

結合起來試試這個:

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

我認爲這仍然將有'太多rows'錯誤,如果子查詢匹配的'templatetbl'多行 – Sodved

0

這應該這樣做。一個簡單的加入,您可以動態構建LIKE字符串。

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

編輯:雖然有人警告,但這可能不是你想要的。由於1templateid將匹配11011,... 21 ... 100