Java ORA-06502:PL/SQL:数字或值错误ORA-06512:在第1行
我使用这个基本代码来调用Oracle函数Java ORA-06502:PL/SQL:数字或值错误ORA-06512:在第1行,java,oracle,oracle11g,Java,Oracle,Oracle11g,我使用这个基本代码来调用Oracle函数 public void basicTest() throws Exception { System.out.println("Basic Oracle Function call test"); // initialize the driver and try to make a connection DriverManager.registerDriver(new oracle.jdbc.driv
public void basicTest() throws Exception
{
System.out.println("Basic Oracle Function call test");
// initialize the driver and try to make a connection
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "admin", "qwerty");
// prepareCall uses ANSI92 "call" syntax
CallableStatement cstmt = conn.prepareCall("{? = call AGENT_STATISTICS_FUNCTION(?)}");
// get those bind variables and parameters set up
cstmt.registerOutParameter(1, Types.VARCHAR);
cstmt.setString(2, "agent");
// now we can do it, get it, close it, and print it
cstmt.execute();
String result = cstmt.getString(1);
conn.close();
System.out.println(result);
}
Oracle功能:
CREATE OR REPLACE FUNCTION AGENT_STATISTICS_FUNCTION(NAMEIN IN VARCHAR2
)
RETURN CLOB
AS
.................
LINE CLOB;
...............
BEGIN
LINE := EMPTY_CLOB();
DBMS_LOB.CREATETEMPORARY(LINE,TRUE);
..............
RETURN LINE;
END AGENT_STATISTICS_FUNCTION;
/
我得到这个错误:
java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:220)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:48)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:938)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1150)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:4901)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:5631)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1385)
at org.sql.engine.osgi.select.TestOracleFunction.extendedTest(TestOracleFunction.java:85)
Results :
Tests in error:
TestOracleFunction.extendedTest:85 » SQL ORA-06502: PL/SQL: numeric or value e...
我尝试添加conn.prepareCall(“begindbms_output.enable(200000);?:=AGENT_STATISTICS_FUNCTION(?);end;”;但结果是一样的。你能提出一些解决办法吗。在SQL Developer中,代码运行正常?您需要注册正确的输出类型:
cstmt.registerOutParameter(1, Types.CLOB);
只是猜测:
cstmt.registerOutParameter(1,Types.CLOB)代码>信息不足。在某个地方,您将clob放入varchar2,它会溢出(超过32k)。或者其他类似的事情,绝对正确。请将其粘贴为答案。@PeterPenzov此答案中已经指出,您的Java代码中存在概念错误;将函数的返回注册为Types.VARCHAR是错误的。您应该使用Oracle的专用CLOB类型。