我有以下類型聲明和Oracle功能:如何使用Java從oracle函數返回嵌套表?
CREATE OR REPLACE TYPE var_outcomes_results IS TABLE OF VARCHAR2(80);
CREATE OR REPLACE FUNCTION getValuesAbove(in_nodeID IN table1.KEY_SL%TYPE,
in_variable IN VARCHAR2)
RETURN var_outcomes_results
IS
currentID table1.KEY_SL%TYPE;
results var_outcomes_results;
currentIndex integer := 0;
BEGIN
currentID := in_nodeID;
WHILE currentID != null
LOOP
FOR outcomeRecord IN
(select distinct a.PARENT, b.NAME, c.OUTCOME
from table1 a
left outer join table2 b on a.KEY_SL = b.KEY_SL
left outer join table3 c on b.VAR_ID = c.VAR_ID
where a.KEY_SL = currentID)
LOOP
currentID := outcomeRecord.PARENT;
IF lower(outcomeRecord.NAME) = lower(in_variable) AND
outcomeRecord.OUTCOME != null THEN
currentIndex := currentIndex + 1;
results(currentIndex) := outcomeRecord.OUTCOME;
END IF;
END LOOP;
END LOOP;
RETURN results;
END;
我有以下的Java功能:
public List<Object> getAboveValues(String variable, Integer nodeID)
{
Connection connection = null;
CallableStatement callableStatement = null;
try
{
connection = dataSource.getConnection();
callableStatement = connection.prepareCall("begin ? := getValuesAbove(?,?); end;");
callableStatement.registerOutParameter(1, OracleTypes.ARRAY);
callableStatement.setInt(2, nodeID);
callableStatement.setString(3, variable);
callableStatement.execute();
System.out.println(callableStatement.getObject(1));
}
catch(SQLException e)
{
logger.error("An Exception was thrown in getAboveValues: " + e);
}
finally
{
closeDataResources(callableStatement, connection);
}
}
然而,當我執行的功能,我收到以下錯誤信息:「ORA -03115:不支持的網絡數據類型或表示「
我在做什麼錯?
任何想法/建議,將不勝感激。
感謝, B.J.
我不認爲一個varchars表是相當於OracleTypes.ARRAY。我已經看到人們使用REF CURSOR來執行此操作,然後該REF CURSOR映射到OracleTypes.CURSOR – CarlG 2010-05-24 16:58:29