【发布时间】:2021-11-24 01:08:50
【问题描述】:
我收到此 SQLException -- ORA-22922 不存在的 LOB 值。
我的情况是:
- 我正在调用一个采用结构数组的过程,
- 结构体包含三种类型,两种是日期,一种是Clob
- 当我使用 Spring 的 simpleJdbcCall 设置 null 而不是 clob 执行该过程时,将执行语句并将数据写入数据库。
- 这表明我的 simpleJdbcCall 设置正确。
这是我创建 clob、array 和 struct 并执行 simpleJdbCall 的代码。
public void insertRecords(List<MyObject> objectList) throws Exception {
Array array = null;
Connection connection = jdbcTemplate.getDataSource().getConnection();
OracleConnection oracleConnection = connection.unwarp(OracleConnection.class);
Object[] arrObj = new Object[objectList.size()];
Object[][] structObj = new Object[objectList.size()][3];
Clob clob = connection.createClob();
for(int loop = 0; loop < objectList.size(); loop++) {
clob.setString(objectList.get(loop).getData);
structObj[loop][0] = objectList.getDate1();
structObj[loop][1] = objectList.getDate2();
structObj[loop][2] = clob; //null;
arrObj[loop] = oracleConnection.createStruct(structName, structObj[loop]);
}
array = oracleConnection.createOracleArray(collectionName, arrObj);
Map<String, Array> inparam = new HashMap<~>;
inparam.put(arrayParamString, array);
//procInsertData is a SimpleJdbcCall
procInsertData.exexute(inparam);
clob.free();
}
意见和解决方案请...
更新:2014 年 5 月 5 日(调试 SQL 语句日志输出):
2014-05-05 11:30:18,126 [main] DEBUG SimpleJdbcCall - JdbcCall call not compiled before execution - invoking compile
2014-05-05 11:30:18,296 [main] DEBUG SimpleJdbcCall - Compiled stored procedure. Call string is [{call MY_DB.WRITE(?)}]
2014-05-05 11:30:18,357 [main] DEBUG SimpleJdbcCall - SqlCall for procedure [write] compiled
2014-05-05 11:30:18,367 [main] DEBUG SimpleJdbcCall - The following parameters are used for call {call MY_DB.WRITE(?)} with: {in_my_objects=org.springframework.jdbc.core.SqlParameterValue@7e4034bd}
2014-05-05 11:30:18,367 [main] DEBUG SimpleJdbcCall - 1: in_my_objects SQL Type 2003 Type Name MY_OBJECT_COLL org.springframework.jdbc.core.SqlParameter
2014-05-05 11:30:18,388 [main] DEBUG StatementCreatorUtils - Overriding type info with runtime info from SqlParameterValue: column index 1, SQL type 2003, type name null
2014-05-05 11:30:18,388 [main] TRACE StatementCreatorUtils - Setting SQL statement parameter value: column index 1, parameter value [oracle.sql.ARRAY@61d6687a], value class [oracle.sql.ARRAY], SQL type 2003
2014-05-05 11:30:18,447 [main] INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2014-05-05 11:30:18,623 [main] INFO SQLErrorCodesFactory - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call MY_DB.WRITE(?)}]; SQL state [99999]; error code [22922]; ORA-22922: nonexistent LOB value
ORA-06512: at "PKG.MY_DB", line 30
ORA-06512: at line 1
; nested exception is java.sql.SQLException: ORA-22922: nonexistent LOB value
ORA-06512: at "PKG.MY_OBJ", line 30
ORA-06512: at line 1
【问题讨论】:
-
我不认为 4. 是 3. 的有效结论。如果 Spring 只是省略了您设置为 null 的 LOB 插入参数怎么办?
insert into t (a,b) values...与insert into t (a,b,lob) values...完全不同。您是否启用了调试日志记录以查看哪些 SQL 语句对数据库有问题? -
感谢@MarcelStör 的输入,我已经尝试在Oracle 上测试插入数据的过程并且它正在工作。此外,在上面的代码中,当创建 struct 时,在创建 db 中的 struct 对象之前会检查这些输入类型。不确定如何在 Spring/Java 端启用调试登录。任何指针?
-
@MarcelStör 添加了调试日志
标签: java oracle jdbctemplate clob