我正在尝试使用 spring-jdbc 调用 oracle 数据库上的存储函数。
这是我试图调用的存储函数:
FUNCTION GET_RESOURCE_LIST RETURN RESOURCE_TAB;
接下来是resource_tab的定义
TYPE RESOURCE_TAB AS TABLE OF TRESOURCE;
接下来是tresource的定义
TYPE TRESOURCE AS OBJECT(
RESOURCE_ID NUMBER(10,0),
RESOURCE_NAME VARCHAR2(100)
)
调用代码
final SimpleJdbcCall call = new SimpleJdbcCall(idmJdbcTemplate).withFunctionName("get_resource_list").declareParameters(new SqlOutParameter(
"RETURN", OracleTypes.STRUCT,
"RESOURCE_TAB",
new SqlReturnType() {
@Override
public Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, String typeName) throws SQLException {
final Struct s = (Struct)cs.getObject(paramIndex);
final Object[] attr = s.getAttributes();
return attr[1];
}
}));
call.compile();
final Collection<String> resources = call.executeFunction(Collection.class);
最后是我收到的堆栈跟踪:
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{? = call WVUID.IDM_REPO_MANUAL.GET_RESOURCE_LIST()}]; SQL state [99999]; error code [17001]; Internal Error: Image is a collection image,expecting ADT; nested exception is java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:969)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
Truncated. see log file for complete stacktrace
Caused By: java.sql.SQLException: Internal Error: Image is a collection image,expecting ADT
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
Truncated. see log file for complete stacktrace
>
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1015)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:953)
... 62 more