2016-07-18 49 views
0

我使用了下面的查詢並得到如下的異常。索引中缺少IN或OUT參數:: 2

值java.sql.SQLException:缺少IN或OUT參數的指數:: 2

請幫助。

select s.ship_id from SHIP S where S.ship_id not in (SELECT ship_id FROM ship WHERE notes1 IS NOT NULL 
AND notes1 IN (select notes1 from ship WHERE SHIP_ID <> ?)) 
AND S.SHIP_ID = ? 
+1

添加您用來調用它的代碼。 –

+0

你需要用兩個參數來調用它。 –

回答

0

這種說法有兩個參數引用:

select s.ship_id 
from SHIP 
where S.ship_id not in (SELECT ship_id 
         FROM ship 
         WHERE notes1 IS NOT NULL AND 
           notes1 IN (select notes1 from ship WHERE SHIP_ID <> ? 
             ) 
        ) and 
     S.SHIP_ID = ?; 

當您執行查詢時,您需要提供他們兩個,即使他們是 - 大概 - 相同。

你似乎在什麼船舶notes1字段是唯一的船隻。您可以用其他方式做到這一點:

select s.shipid 
from (select s.*, 
      min(shipid) over (partition by notes1) as mins, 
      max(shipid) over (partition by notes1) as maxs 
     from ships s 
    ) s 
where mins = maxs and shipid = ?; 
相關問題