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

问题描述 投票:0回答:1

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

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 = ?
sql oracle
1个回答
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 = ?;
© www.soinside.com 2019 - 2024. All rights reserved.