Java Oracle exception - “maximum number of expressions in a list is 1000”

后端 未结 7 722
再見小時候
再見小時候 2020-12-03 05:05

I am passing a list of Strings to my query(SQL query written) to fetch the required data. But I am getting this exception:

ora-01795 maximum number

7条回答
  •  误落风尘
    2020-12-03 05:49

    If you are able to convert your db-side logic from a query into a stored procedure, then you can pass longer arrays (collections) to it.

    Here you can find a brief example how to do it. The link to the docs is outdated, so here's a link to the 9i docs http://docs.oracle.com/cd/B10500_01/java.920/a96654/oraarr.htm#1040124

    import java.io.*;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.*;
    
    public class ArrayDemo
    {
        public static void passArray() throws SQLException
        {
            Connection conn =
                new OracleDriver().defaultConnection();
    
            int intArray[] = { 1,2,3,4,5,6 };
    
            ArrayDescriptor descriptor =
                ArrayDescriptor.createDescriptor( "NUM_ARRAY", conn );
    
            ARRAY array_to_pass =
                new ARRAY( descriptor, conn, intArray );
    
            OraclePreparedStatement ps =
                (OraclePreparedStatement)conn.prepareStatement
                ( "begin give_me_an_array(:x); end;" );
    
            ps.setARRAY( 1, array_to_pass );
    
            ps.execute();
    
        }
    }
    

    and the SQL part

    create or replace type NUM_ARRAY as table of number;
    
    create or replace
    procedure give_me_an_array( p_array in num_array )
    as
    begin
        for i in 1 .. p_array.count
        loop
            dbms_output.put_line( p_array(i) );
        end loop;
    end;
    

提交回复
热议问题