1

我必须在 Oracle 中使用 'OUT' 参数创建一些 java 程序。程序必须是这样的:

create or replace 
procedure SomeProcedure(input1 IN VARCHAR2, result1 OUT VARCHAR2, result2 OUT VARCHAR2)
...
...

我怎么做?我必须如何指定 Java 类和方法?如何从此类和方法创建存储过程?有什么简单的例子吗?

UPD:解决这个问题:

create or replace and compile java source named "TestOutParams" as
public class TestOutParams{
    public static void someMethod(String[] value){
        value[0] = "Hello";
    }
};
/

create or replace procedure TestOutParams(value OUT VARCHAR2) as
language java
NAME 'TestOutParams.someMethod(java.lang.String[])';
/

SQL>var value VARCHAR2(40);
SQL>exec TestOutParams(:value);
PL/SQL procedure successfully completed.
SQL>PRINT value;
VALUE
---------

Hello

我不知道,为什么,但它的工作!

4

1 回答 1

-1

嗯,是这样的;

CallableStatement stmt = null;
stmt = conn.prepareCall("begin SomeProcedure(?,?,?); end;");
stmt.setString(1, new String("value1"));             // Bind 1st input parameter
stmt.setString(2, new String("value2"));          // Bind 2nd input parameter
stmt.registerOutParameter(3, Types.VARCHAR);     // 3rd parameter is OUT
stmt.execute();

String retcod = new String(stmt.getInt(3));
于 2013-10-03T13:36:24.897 回答