Java调用带有记录表的PL / SQL过程



我在 PL/SQL 包中定义了一个记录类型和过程(它接收作为 IN 参数的记录表)如何在 Java 代码中调用此过程?

避免这种类型的 IN 参数更好吗? 也许是引用光标?

通常的做法

是使用临时表。

0 如果关闭自动提交(默认关闭)

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 .......
}