我有一个PL / SQL包中定义的记录类型和过程(收到IN参数记录表) 如何在Java代码中调用此过程?
避免使用这种类型的IN参数会更好吗?也许是REF CURSOR?
答案 0 :(得分:2)
通常使用临时表。
0如果nessesary(默认情况下关闭)
,则设置自动提交1用一些值填充临时表。
2打电话给你的程序。从临时表中读取值。 (IN参数中没有记录)
3提交
//A function to put a value in temporary table
public void addValueToTmp(Connection conn, String value) throws NamingException, SQLException {
CallableStatement cs = conn.prepareCall("{call plsql_function_put_value_in_tmp(?)}");
....... other code .......
....... other code .......
....... other code .......
}
//A function to do something whit a data in temporary table
public void doAllWork(Connection conn) throws NamingException, SQLException {
CallableStatement cs = conn.prepareCall("{call plsql_function_do_something_whith_tmp}");
....... other code .......
....... other code .......
....... other code .......
}
public void mainFunction() throws NamingException, SQLException {
....... other code .......
//Get connection
Connection conn = anyFunctionToGetConnection();
//Fill temporary table
addValueToTmp(conn, value1);
addValueToTmp(conn, value2);
addValueToTmp(conn, value3);
//Do something whith data
doAllWork(conn);
//Commit
conn.commit;
....... other code .......
}