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

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

本文介绍了使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的oracle程序规范

Here is my oracle procedure specifications

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是

TY_APP_REF_ID is

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)
)

我使用Spring JDBC Framework(SimpleJdbcCall对象)来执行上述过程。下面是我声明的代码片段

I am using Spring JDBC Framework(SimpleJdbcCall object) to execute above procedure. 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

to MapSqlParameterSource

 MapSqlParameterSource in = new MapSqlParameterSource();


推荐答案

PeudoCode与我的实现方式相同。

PeudoCode for the same how I achieved.

    # 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);

希望有所帮助。此序列可能根据所使用的sql数据库的要求和类型而有所不同,但基数相同。

Hope it helps. This sequence may vary as per requirement and type of sql database used, but base is same.

这篇关于使用简单的jdbc调用将数组作为输入参数传递给oracle存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 23:19