简体   繁体   English

Oracle存储过程 - Spring集成 - OUT类型对象

[英]Oracle Stored Procedure - Spring Integration - OUT Type Object

Is it possible to have Oracle type object as an output from a stored procedure, calling same using spring integration? 是否可以将Oracle类型对象作为存储过程的输出,使用spring集成调用它?

For example, I have the following in the database: 例如,我在数据库中有以下内容:

create or replace TYPE ESP_TRAINING_REQ_OBJ AS OBJECT 
(
    v_param1 varchar2(25),
    v_param2 varchar2(25)
);

create or replace TYPE ESP_TRAINING_RESP_OBJ AS OBJECT 
(
    v_param1 varchar2(25),
    v_param2 varchar2(25)
);

create or replace PROCEDURE TEST_PROC (
    v_req_obj IN ESP_TRAINING_REQ_OBJ,
    v_resp_obj OUT ESP_TRAINING_RESP_OBJ
) AS
BEGIN
    v_resp_obj := ESP_TRAINING_RESP_OBJ(v_req_obj.v_param2, v_req_obj.v_param1);
    dbms_output.put_line('TEST_PROC');
END;

However, when I try calling it, I'm getting the following exception: 但是,当我尝试调用它时,我得到以下异常:

PLS-00306: wrong number or types of arguments in call to 'TEST_PROC' PLS-00306:调用'TEST_PROC'时参数的数量或类型错误

Please find spring integration configuration bellow: 请参阅下面的弹簧集成配置:

<int-jdbc:stored-proc-outbound-gateway
        id="ESP_TRAINING" request-channel="inputChannel"
        stored-procedure-name="TEST_PROC" data-source="dataSource"
        reply-channel="outputChannel"
        skip-undeclared-results="false" ignore-column-meta-data="true">

        <int-jdbc:sql-parameter-definition name="v_req_obj" direction="IN" type="STRUCT" />
        <int-jdbc:sql-parameter-definition name="v_resp_obj" direction="OUT" type="STRUCT" />

        <int-jdbc:parameter name="v_req_obj" expression="payload.v_req_obj"/>

    </int-jdbc:stored-proc-outbound-gateway>

Please note it works fine if we change SP declaration above, for using STRUCT in request only, for example replacing ESP_TRAINING_RESP_OBJ by a VARCHAR or any other Oracle primitive data type. 请注意,如果我们更改上面的SP声明,仅在请求中使用STRUCT,例如用VARCHAR或任何其他Oracle原始数据类型替换ESP_TRAINING_RESP_OBJ,它可以正常工作。

For Example: 例如:

create or replace PROCEDURE TEST_PROC (
    v_req_obj IN ESP_TRAINING_REQ_OBJ,
    v_status OUT VARCHAR2
) AS
BEGIN
    v_status := v_req_obj.v_param1 || ' and ' || v_req_obj.v_param2;
    dbms_output.put_line('TEST_PROC');
END;

I've fixed it doing following: 我已经修好了以下内容:

  1. Updated spring integration version to 3.0.0.RELEASE, giving support to both type-name and return-type attribues, inside sql-parameter-definition. 将spring集成版本更新为3.0.0.RELEASE,在sql-parameter-definition中支持type-name和return-type attribues。

  2. Updated stored procedured declaration as follows: 更新存储的程序声明如下:

     <int-jdbc:stored-proc-outbound-gateway id="ESP_TRAINING" request-channel="inputChannel" stored-procedure-name="TEST_PROC" data-source="dataSource" reply-channel="outputChannel" skip-undeclared-results="false" ignore-column-meta-data="true"> <int-jdbc:sql-parameter-definition name="v_req_obj" direction="IN" type="STRUCT" /> <int-jdbc:sql-parameter-definition name="v_resp_obj" direction="OUT" type="STRUCT" type-name="ESP_TRAINING_RESP_OBJ" return-type="espTrainingRespObj" /> <int-jdbc:parameter name="v_req_obj" expression="payload.v_req_obj"/> </int-jdbc:stored-proc-outbound-gateway> <beans:bean id="espTrainingRespObj" class="com.hsbc.esp.EspTrainingRespObj"/> 
  3. Changed EspTrainingRespObj to implement SQLReturnType, as follows: 更改了EspTrainingRespObj以实现SQLReturnType,如下所示:

     public class EspTrainingRespObj implements SqlReturnType { private String param1; private String param2; public Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, String typeName) throws SQLException { Object[] attributes = ((STRUCT) cs.getObject(paramIndex)).getAttributes(); this.param1 = (String) attributes[0]; this.param2 = (String) attributes[1]; return this; } ... } 

The return-type on the <int-jdbc:sql-parameter-definition> for OUT param and SqlReturnStruct must help you to solve the issue. OUT param和SqlReturnStruct<int-jdbc:sql-parameter-definition>上的return-type必须帮助您解决问题。

The test-case in the Framework source codes contains this sample for CLOB handling: 框架源代码中的测试用例包含此CLOB处理示例:

<int-jdbc:stored-proc-outbound-gateway request-channel="getMessageChannel"
                                       data-source="dataSource"
                                       stored-procedure-name="GET_MESSAGE"
                                       ignore-column-meta-data="true"
                                       expect-single-result="true"
                                       reply-channel="output2Channel">
    <int-jdbc:sql-parameter-definition name="message_id"/>
    <int-jdbc:sql-parameter-definition name="message_json" type="CLOB" direction="OUT" type-name="" return-type="clobSqlReturnType"/>
    <int-jdbc:parameter name="message_id" expression="payload"/>
</int-jdbc:stored-proc-outbound-gateway>

<bean id="clobSqlReturnType" class="org.mockito.Mockito" factory-method="spy">
    <constructor-arg>
        <bean class="org.springframework.integration.jdbc.storedproc.ClobSqlReturnType"/>
    </constructor-arg>
</bean>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将oracle对象类型传递给j​​ava存储过程 - Pass oracle object type to java stored procedure 使用EclipseLink在Oracle中调用具有复杂对象类型参数的存储过程 - Calling stored procedure in Oracle with complex object type parameters using EclipseLink 使用oracle对象参数调用oracle存储过程 - Call oracle stored procedure with oracle object parameter 使用spring存储过程调用oracle存储过程 - Calling oracle stored procedure using spring stored procedure 退货清单<String>使用来自具有自定义对象的 Oracle 存储过程的 Spring jdbc - Return List<String> using Spring jdbc from Oracle stored procedure having custom object 使用Spring的org.springframework.jdbc.object.StoredProcedure调用Oracle存储过程 - call Oracle stored procedure using Spring's org.springframework.jdbc.object.StoredProcedure 从存储过程返回两个用户定义类型对象并使用 spring-data-jpa 在存储库级别调用存储过程 - Returning two user define type object from stored procedure and calling stored procedure at repository level using spring-data-jpa 尝试使用 Spring Data JPA 运行存储过程时,“类型不能为空”异常 - `Type cannot be null` exception when trying to run out Stored Procedure using Spring Data JPA 使用 OUT 参数调用存储过程 Spring Spring JPA 2.* - Calling stored procedure using OUT parameter with Spring Spring JPA 2.* 从Hibernate调用带有OUT参数的Oracle存储过程 - Oracle stored procedure with OUT parameters calling from Hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM