需要帮助。我试图从java调用pl / sql函数。 pl / sql函数将IN OUT CHAR参数作为参数之一。我只发送一个字符并将该char值分配给临时char值。但是得到pl / sql数值错误,进一步调试显示参数的长度如32767.无法得到如何解决它。我使用Oracle 12c db和ojdbc7.jar连接到它。下面是java代码和PL / SqL代码。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;
public class TestInOutParam {
public static void main(String[] args){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@ragh:1521:inst1","schema1","schema1");
OracleCallableStatement procCall = (OracleCallableStatement)con.prepareCall("{? = call TEMPPROC (?,?,?,?)}");
String a = "ragh";
String b="n";
Integer c = 50;
procCall.registerOutParameter(1, Types.INTEGER);
procCall.registerOutParameter(2, Types.VARCHAR);
procCall.registerOutParameter(3, Types.CHAR, 0, 1);
procCall.registerOutParameter(4, Types.INTEGER);
procCall.registerOutParameter(5, Types.DATE);
procCall.setString(2, a);
procCall.setString(3, b);
procCall.setInt(4, c);
procCall.setDate(5, getCurrentDate());
procCall.executeUpdate();
}catch(Exception e){ System.out.println(e);}
}
private static java.sql.Date getCurrentDate() {
java.util.Date today = new java.util.Date();
return new java.sql.Date(today.getTime());
}
}
下面是PL / SQL代码,
CREATE TABLE TEMP
(
MSG VARCHAR2(3000 BYTE),
DT DATE
)
/
CREATE OR REPLACE function tempproc(a in out varchar, b in out char, c in out integer, d in out date) return integer
is
errm varchar2(3000);
tempb char(32);
tempa varchar2(10);
tempc integer;
tempd date;
result integer;
begin
tempa := a;
insert into temp values('varchar value'||tempa, sysdate); commit;
tempc := c;
insert into temp values('integer value'||tempc, sysdate); commit;
tempd := d;
insert into temp values('date value', tempd); commit;
tempb := b;
insert into temp values('char value'||tempb, sysdate); commit;
commit;
return result;
exception
when others then
errm := sqlerrm;
insert into temp values ('ex'||errm, sysdate);
commit;
return 2;
end;
/