0

Environment: oracle 11g, spring-jdbc-3.2.2-RELEASE.jar, JDK 1.7, Oracle UCP driver.

I have a stored procedure which insert record to a table with CLOB column. The SP has a CLOB input argument among other IN and OUT arguments. My Java code uses Spring StoredProcedure to call the stored procedure:

public class MyClass extends StoredProcedure {
    public MyClass(){
       .....
       declareParameter(new SqlParameter("content", Types.CLOB));
       .....
    }

    public void insert(){
       HashMap<String,Object> params = new HashMap<String, Object>(37);
       String bigContent = ....; // which contains ASCII chars in my test
       ....
       params.put("content", new SqlLobValue(bigContent));
       ....
       execute(params);
    }
}

The code works fine if bigContent has < 32k chars. If bigContent has, say 50K, chars, it didn't work. I also tested using jdbcTemplate and SqlLobValue to insert into the table directly, everything works fine with bigContent has 50K chars.

I want to use the SP as it does a whole bunch of other stuff and is more efficient than invoking multiple SQL insert, update, and query statements separately.

Anyone know how to get it to work with SP? Or this is the limit I have to handle it differently if bigContent has > 32K chars?

wang.aurora
  • 255
  • 3
  • 8
  • 1
    my understanding is that Oracle does not put 32K limit on CLOB IN stored procedure argument for programming libraries. This is likely a Spring side issue. – wang.aurora Apr 26 '15 at 01:45

4 Answers4

1

It depend on your version of Oracle:

  • < 10.1: you can put the SetBigStringTryClob property to true in your DriverManager.
  • >= 10.1: you can use OraclePreparedStatement.setStringForClob doc here.

Also, this article may help you.

grebesche
  • 511
  • 1
  • 3
  • 14
0

The limit for CLOB in Oracle is 176TB. 32KB is limit for VARCHAR. Your code somewhere uses implicit conversion from VARCHAR to CLOB. In Oracle CLOB must be OUTPUT paramater - even if you are inserting it. Oracle's API assumes that you create empty_clob() on database side, then you return a LOB locator to aplication. The application then uses this LOB locator as filehandle.

This behaviour is different from other databases.

ibre5041
  • 4,903
  • 1
  • 20
  • 35
0

PL/SQL has a hard limit of 32k chars if you send the data as a character string. If the parameter is a CLOB you can first create a temp LOB, fill it up with data and then call your PL/SQL procedure with the CLOB object.

Jean de Lavarene
  • 3,461
  • 1
  • 20
  • 28
0

We had similar issue, but then we discovered the root cause inside the PL/SQL - mixing VARCHAR2 and CLOB types for the "large" parameter.

So finally we left the Java code as it was - even using String and not Clob for passing the large parameter into Java (using Spring StoredProcedure).