Getting ORA-06502 or ORA-01461 When Calling Stored Procedure That Has a CHAR OUT Parameter From JDBC (Doc ID 1300792.1)

Last updated on MAY 19, 2017

Applies to:

JDBC - Version 11.2.0.2.0 and later
Information in this document applies to any platform.
***Checked for relevance on 12-Dec-2013***
***Checked for relevance on 21-May-2015*** ( retested using database and JDBC driver version 12.1.0.2)

Symptoms


A simple JDBC standalone testcase gets ORA-06502 PL/SQL: numeric or value error: character string buffer too small (when database parameter blank_trimming=false) or ORA-01461: can bind a LONG value only for insert into a LONG column (when database parameter blank_trimming=true).
The error is triggered by a CallableStatement executing a PL/SQL stored procedure that has an argument of CHAR(10) defined through a %TYPE which is based on a database table column.

JDBC code excerpt:

String sql = "{CALL P_TEST_PROCEDURE(?)}";
stmt = oracleConn.prepareCall(sql);
stmt.registerOutParameter(1, OracleTypes.CHAR);
stmt.execute();
String o_res = stmt.getString(1);


Table and stored procedure:


SQL> create table TEST_CHAR( "VAL" char(10) NOT NULL);
Table created.

SQL> create or replace
PROCEDURE P_TEST_PROCEDURE
( o_Res OUT TEST_CHAR.VAL%TYPE
) AS

v_res VARCHAR2(10);

BEGIN

v_res := 'char';
o_res := v_res;
-- reassigning varchar from char will fail with ORA-06512 only when called from java with blank_trimming=false
v_res := o_res;

-- reassigning varchar from char will fail with ORA-01461 only when called from java
insert into test_char values(o_res);

END P_TEST_PROCEDURE;
/



Error Stack:

Exception in thread "main" java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "SCOTT.P_TEST_PROCEDURE", line 12
ORA-06512: at line 1
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:204)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1007)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3677)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4694)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1086)
at RunTest.callProcedure(RunTest.java:55)
at RunTest.main(RunTest.java:34)

Changes

The issue appears to occur with all versions of the JDBC Driver.

 

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms