我正在从JPA EclipseLink调用存储过程。存储过程返回三个输出变量,一种是游标类型,另外两种是变量。我能够从游标中获得返回的值,但不能获得其他两个值。
这是存储过程的一部分(示例):
create or replace PROCEDURE PROCEDURE1 (
Variable1 IN VARCHAR2,
Variable12 IN VARCHAR2,
Variable13 IN VARCHAR2,
Variable14 IN VARCHAR2,
p_xml_result OUT SYS_REFCURSOR,
p_errorcode OUT NUMBER,
p_errorMessage OUT VARCHAR2)
IS
-- Declare variable
ERRSQL VARCHAR2 (80);
NOSTRAECCEZIONE EXCEPTION;
ERROR_ONE EXCEPTION;
V_AREA VARCHAR2(40);
BEGIN
SELECT AREA
INTO V_AREA
FROM Employee
WHERE Employee_CODE = P_EmployeeCode;
OPEN p_xml_result FOR
<Some query to get data>
p_errorcode := 0;
p_errorMessage := NULL;
EXCEPTION
WHEN NO_DATA_FOUND THEN
p_errorcode := 100;
p_errorMessage := 'generic error';
WHEN OTHERS THEN
p_errorcode := 102;
p_errorMessage := SQLERRM;
Java代码:
StoredProcedureCall procCall = new StoredProcedureCall();
procCall.setProcedureName("getSpecialOffers");
procCall.addNamedArgument("Variable1","Variable1",String.class);
procCall.addNamedArgument("Variable2", "Variable12", String.class);
procCall.addNamedArgument("Variable13", "Variable13", String.class);
procCall.addNamedArgument("Variable14", "Variable14", String.class);
procCall.addNamedOutputArgument("p_xml_result", "p_xml_result", OracleTypes.CURSOR);
procCall.addNamedOutputArgument("p_errorcode", "p_errorcode", Integer.class);
procCall.addNamedOutputArgument("p_errorMessage", "p_errorMessage", String.class);
Session session = ((JpaEntityManager)_em).getActiveSession();
ValueReadQuery query = new ValueReadQuery();
query.setCall(procCall);
query.addArgument("Variable1");
query.addArgument("Variable12");
query.addArgument("Variable13");
query.addArgument("Variable14");
Vector parameters = new Vector();
parameters.addElement(Variable1);
parameters.addElement(Variable12);
parameters.addElement(Variable13);
parameters.addElement(Variable14);
Object qResult = null;
qResult = session.executeQuery(query,parameters);
Vector vec=(Vector) qResult;
ArrayRecord arrayrec =(ArrayRecord) vec.get(0);
p_xml_result返回四个字段,我可以将其提取为arrayrec.get(“ VariableXYZ”)。并且arrayrec也只存在从游标返回的这四个变量。但是我想在所有情况下都在代码中访问p_errorcode的值。你能帮我吗?
答案 0 :(得分:0)
通过将ValueReadQuery更改为DataReadQuery,获得了所需的输出参数。