Oracle教程:ORA-01795的原因及解決辦法

來源:互聯網
上載者:User

系統報出一SQL異常,內容如下:

java.sql.SQLException: ORA-01795: maximum number of expressions in a list is 1000

找出拋異常時執行的SQL語句,貌不驚人啊,很平常一SQL語句,內容類別似:SELECT * FROM DUAL T WHERE T.DUMMY IN ('1', '2', '3', ...),只是IN後括弧裡的主索引值多了些,其它沒啥特別的。

看ORA-01795中給出的內容是SQL語句的 expressions 中list接受的最大值是1000,查了下ORA-01795的說明,確定問題出在IN後括弧裡的主索引值超過1000上。

解決思路大至有兩種,一種是換用JOIN或者EXIST,另一種是仍然用IN,但是把條件分成多個少於1000的IN即:SELECT * FROM DUAL T WHERE T.DUMMY IN ('1', '2', '3',...,'1000') OR IN ('1001', '1002', ..., '2000') OR ...



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.