今天在工作中使用mybatis plus的selectBatchIds(List<Integer> ids)方法時,oracle報了ORA-01795的錯。
則是因為oracle中使用 in 有限制,后面集合數目不能大於1000個,否則就會報錯。
所以可以使用這種形式來規避。
select ... from ... where id in (1,2...1000) or in (1001,1002...2000) or (2001....
所以當id集合大於1000時候,就不能用Mybatis plus了,要在xml中手寫查詢方法。
如下圖:
經測試,最后的運行結果應該是這樣:
select ... from ... where id in (1,2...998,null) or in (999...1997,null) or (1998....
如果在Sql中不加上NULL,可能會形成這樣的sql,直接報錯。
select ... from ... where id in (1,2...998,) or in (999)