2012-12-20 48 views
0

我想通過單個參數傳遞多個值。參數中的多個值 - SQL(Oracle)


select 
id, 
item_number 
from AGILE.item_p2p3_query where subclass='2477110' and date32 is not null 
and item_number in : p **// passing one parameter would work. But when I pass two parameters like EN 60439-1:1999,EN 60439-3:1991 doesn't seem to work** 
--in ('EN 60439-3:1991','EN 60439-1:1999') // this will work 

請建議僅SQL建議,而不是PL/SQL,我會在報表中使用此。

+1

也許這個職位可能會幫助http://stackoverflow.com/questions/13580245/sending-an-array-of-values-to-oracle-procedure-to-use-in-where-in-clause –

回答

2

我假設你將值綁定到查詢,因爲它有效時有一個值,但失敗時有兩個。這是如何做,我綁定列表中的變量的問題。有一些解決方案,但我喜歡的,不涉及PLSQL是:

with id_generator 
    as 
    (
     SELECT regexp_substr(:txt, '[^,]+', 1, LEVEL) token 
     FROM dual 
     CONNECT BY LEVEL <= length(:txt) - length(REPLACE(:txt, ',', '')) + 1 
    ) 
    select u.id, u.username 
    from users u, id_generator g 
    where u.id = g.token; 

綁定您的逗號分隔字符串作爲值:TXT,然後構建您的查詢作爲加盟。

充分說明 - http://betteratoracle.com/posts/20-how-do-i-bind-a-variable-in-list

0

這可能會幫助 - PAS deptnos的任何有效的列表LK 10,20 ...:

Select * From scott.emp 
Where deptno IN (&deptno) 
/

如果傳遞一個字符串,然後使用引號... IN(」 & ename') 謝謝。