简体   繁体   English

使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程

[英]Pass array as input parameter to an oracle stored procedure using simple jdbc call

Here is my oracle procedure specifications 这是我的oracle程序规范

CREATE OR REPLACE PACKAGE PKG_RE_FI AS

  PROCEDURE PRC_RE_FI_DETAILS(P_FAN_NO       IN VARCHAR2,
                              P_REF_ID       IN TY_APP_REF_ID,
                              P_COMMENTS     IN VARCHAR2,
                              P_BILLING_FLAG IN VARCHAR2,
                              P_STATUS       OUT VARCHAR2);
END PKG_RE_FI;

TY_APP_REF_ID is TY_APP_REF_ID为

CREATE OR REPLACE TYPE ty_app_REF_ID as varray(500) of obj_array_ref_id

CREATE OR REPLACE TYPE obj_array_ref_id  AS OBJECT(
app_ref_id VARCHAR2(100)
)

I am using Spring JDBC Framework(SimpleJdbcCall object) to execute above procedure. 我正在使用Spring JDBC Framework(SimpleJdbcCall对象)执行上述过程。 Below is the code snippet in which i have declared 以下是我在其中声明的代码段

      this.reFIJdbcCall =  new SimpleJdbcCall(dataSource).withCatalogName("PKG_RE_FI").
              withProcedureName("PRC_RE_FI_DETAILS").declareParameters(new SqlParameter("P_FAN_NO", Types.VARCHAR),
                        new SqlParameter("P_REF_ID", Types.ARRAY),
                        new SqlParameter("P_COMMENTS", Types.VARCHAR),
                        new SqlParameter("P_BILLING_FLAG", Types.VARCHAR),
                        new SqlOutParameter("P_STATUS", Types.VARCHAR)
              );

How should i pass array to the 我应该如何将数组传递给

new SqlParameter("P_REF_ID", Types.ARRAY),

to MapSqlParameterSource 到MapSqlParameterSource

 MapSqlParameterSource in = new MapSqlParameterSource();

The Spring Data JDBC Extensions project has some support that makes this easier. Spring Data JDBC Extensions项目提供了一些支持,使这变得更加容易。 Take a look at the reference manual for passing in an Oracle ARRAY type . 查看有关传递Oracle ARRAY类型参考手册

PeudoCode for the same how I achieved. PeudoCode同样是如何实现的。

    # 1.You will require a structDescriptor object for an object equivalent in pl sql like :

    StructDescriptor structDes= new StructDescriptor("<schemaname in caps>.<sql_object_name>", connectionObject);

    # 2. You will need to pass one object values such name, class, id to an object array in order and accordance to 'sql_object_name' object. 

    For exmaple:
    STRUCT[] structArray=new STRUCT[<ListObj>.size()];
    int index=0;
    for (a in ListObj){

    Object[] object=new Object[]{a.getName(),a.getId()};
    STRUCT struct=new STRUCT(structDes ,connectionObject,object);
               structArray[index]=struct;
               index++;

    }

    ArrayDescriptor arrayDes=ArrayDescriptor.createDescriptor(
        "<Schema name>.<table object from sql>", connectionObject);

    ARRAY array=new ARRAY(arrayDes,connectionObject, structArray);

   then pass it to proc 

   .declareParameters(
   new SqlInOutParameter("<parameter to proc name>",OracleTypes.ARRAY,"
   <schema name>.<sql_array_or_table_obj>"))

   like 
   Hashmap<String, Object> map= new HashMap<>();
   map.put("<parameter to proc name>",array);
   psStatement.execute(map);

Hope it helps. 希望能帮助到你。 This sequence may vary as per requirement and type of sql database used, but base is same. 该顺序可能会根据使用的sql数据库的要求和类型而有所不同,但是基础是相同的。

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

相关问题 Oracle 11g:使用简单的 jdbc 调用将数组作为输入参数传递给 oracle 存储过程 - Oracle 11g: Pass array as input parameter to an oracle stored procedure using simple jdbc call 使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程 - Pass array as input parameter to an oracle stored procedure using simple jdbc call 使用 jdbc 模板的简单 JDBC 调用调用 oracle 存储过程时面临的问题 - Issue Facing in calling oracle stored procedure using Simple JDBC call of jdbc template 使用JDBC以自定义类型输入参数调用PL / SQL存储过程,所有字段均为空 - Using JDBC to call a PL/SQL stored procedure with custom type input parameter, all fields are null JDBC取消Oracle存储过程调用 - JDBC cancel Oracle stored procedure call 使用oracle对象参数调用oracle存储过程 - Call oracle stored procedure with oracle object parameter 如何使用JDBC / Spring调用Oracle存储过程,其中一些参数类型是用户定义的? - How can I call an Oracle stored procedure with JDBC/Spring where some of the parameter types are user defined? 使用 JdbcTemplate 将 Java 数组传递给 ORACLE 存储过程 - Pass an Java Array to ORACLE Stored Procedure using JdbcTemplate JDBC存储过程调用 - JDBC stored procedure call 如何使用JPA 2在存储过程中将复杂对象数组作为IN参数传递 - How to pass Array of complex objects as a IN parameter in a stored procedure using JPA 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM