【问题标题】:Pass array as input parameter to an oracle stored procedure using simple jdbc call使用简单的 jdbc 调用将数组作为输入参数传递给 oracle 存储过程
【发布时间】:2014-12-26 15:09:56
【问题描述】:

这是我的 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 是

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 对象)来执行上述过程。下面是我声明的代码sn-p

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

我应该如何将数组传递给

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

到 MapSqlParameterSource

 MapSqlParameterSource in = new MapSqlParameterSource();

【问题讨论】:

    标签: java spring oracle stored-procedures spring-jdbc


    【解决方案1】:

    Spring Data JDBC Extensions 项目有一些支持,使这更容易。看看reference manual for passing in an Oracle ARRAY type

    【讨论】:

    • 我会尝试这个并接受答案,如果它有效。谢谢
    • 嗨..在我的例子中,除了提到的数组之外,还有很少的输入参数。如何做到这一点?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-12-09
      • 2011-02-22
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      • 2016-02-02
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多