2013-05-10 76 views
0

我使用的是oracle 10g,我有一個問題給你。sql,子查詢到一個LIKE()運算符

是否有可能將子查詢插入LIKE()運算符?

例:SELECT* FROM users u WHERE u.user_name LIKE (subquery here);

我已經試過之前 - 這tolds我說我的查詢didnt wokrs>

SELECT * FROM dictionary WHERE TABLE_NAME 
LIKE (Select d.TABLE_NAME from dictionary d 
     where d.COMMENTS LIKE '%table%' 
    ) 
WHERE ROWNUM < 100; 

- >ORA-00933: la commande SQL ne se termine pas correctement(SQL查詢不正確完成)和最後WHERE不在。

我知道這是一個愚蠢的查詢,但是那只是我正在尋找一個答案的問題=)

回答

4

我猜你想,因爲你要多個值在同一時間比較做到這一點。使用子查詢(如你的例子)不會解決這個問題。

這裏是另一種方法:

select * 
from users u 
where exists (<subquery here> where u.user_name like <whatever>) 

或使用顯式連接:

select distinct u.* 
from users u join 
    (subquery here 
    ) s 
    on u.user_name like s.<whatever> 
1

如果你的子查詢返回超過1行,如果此行不是一個字符串,它不會工作在你的情況下使用IN而不是LIKE

1

只有當你的子查詢返回一個值