<tfoot id='4htxV'></tfoot>

<i id='4htxV'><tr id='4htxV'><dt id='4htxV'><q id='4htxV'><span id='4htxV'><b id='4htxV'><form id='4htxV'><ins id='4htxV'></ins><ul id='4htxV'></ul><sub id='4htxV'></sub></form><legend id='4htxV'></legend><bdo id='4htxV'><pre id='4htxV'><center id='4htxV'></center></pre></bdo></b><th id='4htxV'></th></span></q></dt></tr></i><div id='4htxV'><tfoot id='4htxV'></tfoot><dl id='4htxV'><fieldset id='4htxV'></fieldset></dl></div>
  • <legend id='4htxV'><style id='4htxV'><dir id='4htxV'><q id='4htxV'></q></dir></style></legend>
          <bdo id='4htxV'></bdo><ul id='4htxV'></ul>

        <small id='4htxV'></small><noframes id='4htxV'>

      1. 如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?

        时间:2023-10-27

        <legend id='s8ZpS'><style id='s8ZpS'><dir id='s8ZpS'><q id='s8ZpS'></q></dir></style></legend>
          <bdo id='s8ZpS'></bdo><ul id='s8ZpS'></ul>

                <tbody id='s8ZpS'></tbody>

                1. <small id='s8ZpS'></small><noframes id='s8ZpS'>

                2. <i id='s8ZpS'><tr id='s8ZpS'><dt id='s8ZpS'><q id='s8ZpS'><span id='s8ZpS'><b id='s8ZpS'><form id='s8ZpS'><ins id='s8ZpS'></ins><ul id='s8ZpS'></ul><sub id='s8ZpS'></sub></form><legend id='s8ZpS'></legend><bdo id='s8ZpS'><pre id='s8ZpS'><center id='s8ZpS'></center></pre></bdo></b><th id='s8ZpS'></th></span></q></dt></tr></i><div id='s8ZpS'><tfoot id='s8ZpS'></tfoot><dl id='s8ZpS'><fieldset id='s8ZpS'></fieldset></dl></div>
                  <tfoot id='s8ZpS'></tfoot>
                3. 本文介绍了如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经在谷歌上搜索了一段时间,似乎找不到任何真正的答案.

                  I have been googling this for a while and cannot seem to find any real answers.

                  我有一个 Oracle 存储过程,它有许多 in 参数,这些参数的类型是表行类型的表.例如:

                  I have an Oracle stored procedure that has a number of in parameters that have a type that is table of the table rowtype. So for example:

                  在包装中声明:

                  TYPE param1_type_t IS TABLE OF table1%ROWTYPE;
                  TYPE param2_type_t IS TABLE OF table2%ROWTYPE;
                  TYPE param3_type_t IS TABLE OF table3%ROWTYPE;
                  

                  Oracle 程序:

                  PROCEDURE my_proc
                  (
                     parameter1    IN param1_type_t,
                     parameter2    IN param2_type_t,
                     parameter3    IN param3_type_t
                  )
                  

                  在 Java 方面,我有 3 个对应的对象列表,代表在 Java 中填充的每个参数.这种场景下可以用MyBatis调用Oracle过程吗?

                  On the java side, I have 3 corresponding Lists of objects representing each of the parameters that are populated in Java. Is it possible to call the Oracle procedure using MyBatis in this scenario?

                  <update id="callOracleSP" statementType="CALLABLE">
                      {CALL my_proc( #{param1, mode=IN},
                                     #{param2, mode=IN},
                                     #{param3, mode=IN}
                                   )
                      }
                  </update>
                  

                  对象本身是简单的 VO,具有 String 和 Integer 属性以及它们各自的 getter 和 setter.

                  The objects themselves are simple VOs with String and Integer properties and their respective getters and setters.

                  我不确定如何继续.我是否需要以某种方式将 Java 对象列表映射到 Oracle 类型?

                  I am not really sure how to proceed. Do I need to somehow map the Java object lists to the Oracle types?

                  推荐答案

                  我不知道您是否已经这样做了,但是您需要定义 Oracle 对象.

                  I can't tell if you do already or not, but you'll need Oracle objects defined.

                  CREATE OR REPLACE TYPE SCHEMA."YOUR_OBJECT" AS OBJECT
                  (
                      field_one    varchar2(50),
                      field_two    varchar2(100)
                  );
                  /
                  CREATE OR REPLACE TYPE SCHEMA."YOUR_OBJECT_ARRAY" AS TABLE OF YOUR_OBJECT;
                  /
                  

                  然后您可以编写类型处理程序来将 Java 对象映射到 Oracle 对象.

                  Then you can write type handlers to map the Java objects to the Oracle objects.

                  import oracle.sql.ARRAY;
                  import oracle.sql.ArrayDescriptor;
                  import oracle.sql.STRUCT;
                  import oracle.sql.StructDescriptor;
                  ....
                  public class YourTypeHandler implements TypeHandler
                  {
                  ....
                      public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException
                      {
                          List<YourObject> objects = (List<YourObject>) parameter;
                  
                          StructDescriptor structDescriptor = StructDescriptor.createDescriptor("YOUR_OBJECT", ps.getConnection());
                  
                          STRUCT[] structs = new STRUCT[objects.size()];
                          for (int index = 0; index < objects.size(); index++)
                          {
                              YourObject pack = packs.get(index);
                              Object[] params = new Object[2];
                              params[0] = pack.getFieldOne();
                              params[1] = pack.getFieldTwo();
                              STRUCT struct = new STRUCT(structDescriptor, ps.getConnection(), params);
                              structs[index] = struct;
                          }
                  
                          ArrayDescriptor desc = ArrayDescriptor.createDescriptor("YOUR_OBJECT_ARRAY", ps.getConnection());
                          ARRAY oracleArray = new ARRAY(desc, ps.getConnection(), structs);
                          ps.setArray(i, oracleArray);
                      }
                  }
                  

                  然后调用程序,

                  call your_proc
                  (
                  #{yourObjects, javaType=Object, jdbcType=ARRAY, jdbcTypeName=YOUR_OBJECT_ARRAY, mode=IN, typeHandler=YourObjectArrayTypeHandler}
                  )
                  

                  这篇关于如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:设置变量结果,来自查询 下一篇:如何在 VS 2015 中调试存储过程?

                  相关文章

                    <tfoot id='hLrBT'></tfoot>
                      <i id='hLrBT'><tr id='hLrBT'><dt id='hLrBT'><q id='hLrBT'><span id='hLrBT'><b id='hLrBT'><form id='hLrBT'><ins id='hLrBT'></ins><ul id='hLrBT'></ul><sub id='hLrBT'></sub></form><legend id='hLrBT'></legend><bdo id='hLrBT'><pre id='hLrBT'><center id='hLrBT'></center></pre></bdo></b><th id='hLrBT'></th></span></q></dt></tr></i><div id='hLrBT'><tfoot id='hLrBT'></tfoot><dl id='hLrBT'><fieldset id='hLrBT'></fieldset></dl></div>
                      <legend id='hLrBT'><style id='hLrBT'><dir id='hLrBT'><q id='hLrBT'></q></dir></style></legend>

                      <small id='hLrBT'></small><noframes id='hLrBT'>

                      • <bdo id='hLrBT'></bdo><ul id='hLrBT'></ul>