1

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

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

4

1 回答 1

2

通常的做法是使用临时表。

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 .......
}
于 2012-04-25T10:37:35.847 回答