索引:: 2处缺少IN或OUT参数

时间:2016-07-18 12:52:47

标签: sql oracle

我使用了以下查询并获得如下异常。

  

java.sql.SQLException:索引:: 2

时缺少IN或OUT参数

请帮忙。

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 :(得分:1)

此语句有两个参数引用:

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 = ?;