Java下OracleSQLForField_IN

Java下OracleSQL For Field_IN

SQL指令範例

1
SELECT * FROM world where position IN (SELECT /*+ CARDINALITY(T1, 100) */ * FROM TABLE(?) T1);

Oracle Object 轉換

1
2
3
4
5
6
7
8
9
10
11
12
13
int[] positions = new int[2];
positions[0] = 1;
positions[1] = 8;

OracleUtils.getOracleARRAY(conn, "NUMBER_ARRAY", positions);

public static ARRAY getOracleARRAY(Connection conn, String descriptor, Object elements)
throws SQLException {
Connection nativeConn = OracleUtils.getNativeConnection(conn);
ArrayDescriptor des = ArrayDescriptor.createDescriptor(descriptor, nativeConn);

return new ARRAY(des, nativeConn, elements);
}

資料庫建立Type NUMBER_ARRAY

1
2
3
4
5
CREATE OR REPLACE TYPE "{TABLE}"."NUMBER_ARRAY" AS TABLE OF NUMBER;

Introduction to Oracle NUMBER data type
The precision is the number of digits in a number. It ranges from 1 to 38.
The scale is the number of digits to the right of the decimal point in a number. It ranges from -84 to 127.