1. <legend id='DuQut'><style id='DuQut'><dir id='DuQut'><q id='DuQut'></q></dir></style></legend>

      <tfoot id='DuQut'></tfoot>

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

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

      1. 带有 IN 子句参数的 Oracle 存储过程

        时间:2023-09-19
      2. <small id='17rvu'></small><noframes id='17rvu'>

          <tbody id='17rvu'></tbody>
        <i id='17rvu'><tr id='17rvu'><dt id='17rvu'><q id='17rvu'><span id='17rvu'><b id='17rvu'><form id='17rvu'><ins id='17rvu'></ins><ul id='17rvu'></ul><sub id='17rvu'></sub></form><legend id='17rvu'></legend><bdo id='17rvu'><pre id='17rvu'><center id='17rvu'></center></pre></bdo></b><th id='17rvu'></th></span></q></dt></tr></i><div id='17rvu'><tfoot id='17rvu'></tfoot><dl id='17rvu'><fieldset id='17rvu'></fieldset></dl></div>
          • <bdo id='17rvu'></bdo><ul id='17rvu'></ul>

                  <legend id='17rvu'><style id='17rvu'><dir id='17rvu'><q id='17rvu'></q></dir></style></legend>
                  <tfoot id='17rvu'></tfoot>
                  本文介绍了带有 IN 子句参数的 Oracle 存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何创建一个 Oracle 存储过程,它接受用于提供 IN 子句的可变数量的参数值?

                  How can I create an Oracle stored procedure which accepts a variable number of parameter values used to feed a IN clause?

                  这就是我想要达到的目标.我不知道如何在 PLSQL 中声明以传递我要更新的行的主键变量列表.

                  This is what I am trying to achieve. I do not know how to declare in PLSQL for passing a variable list of primary keys of the rows I want to update.

                  FUNCTION EXECUTE_UPDATE
                    ( <parameter_list>
                     value IN int)
                    RETURN  int IS
                  BEGIN 
                      [...other statements...]
                      update table1 set col1 = col1 - value where id in (<parameter_list>) 
                  
                      RETURN SQL%ROWCOUNT ;
                  END;
                  

                  另外,我想从 C# 调用这个过程,所以它必须与 .NET 功能兼容.

                  Also, I would like to call this procedure from C#, so it must be compatible with .NET capabilities.

                  谢谢,罗伯特

                  推荐答案

                  使用 CSV 可能是最简单的方法,假设您可以 100% 确定您的元素本身不包含字符串.

                  Using CSV is probably the simplest way, assuming you can be 100% certain that your elements won't themselves contain strings.

                  另一种可能更健壮的方法是创建一个自定义类型作为字符串表.假设您的字符串不超过 100 个字符,那么您可以:

                  An alternative, and probably more robust, way of doing this is to create a custom type as a table of strings. Supposing your strings were never longer than 100 characters, then you could have:

                  CREATE TYPE string_table AS TABLE OF varchar2(100);
                  

                  然后您可以将这种类型的变量传递到您的存储过程中并直接引用它.在你的情况下,是这样的:

                  You can then pass a variable of this type into your stored procedure and reference it directly. In your case, something like this:

                  FUNCTION EXECUTE_UPDATE(
                      identifierList string_table,
                      value int)
                  RETURN int
                  IS
                  BEGIN
                  
                      [...other stuff...]
                  
                      update table1 set col1 = col1 - value 
                      where id in (select column_value from table(identifierList));
                  
                      RETURN SQL%ROWCOUNT;
                  
                  END
                  

                  table() 函数将您的自定义类型转换为具有单列COLUMN_VALUE"的表,然后您可以像对待任何其他表一样对待它(联接也是如此,在这种情况下,子选择).

                  The table() function turns your custom type into a table with a single column "COLUMN_VALUE", which you can then treat like any other table (so do joins or, in this case, subselects).

                  这样做的好处在于,Oracle 将为您创建一个构造函数,因此在调用存储过程时,您可以简单地编写:

                  The beauty of this is that Oracle will create a constructor for you, so when calling your stored procedure you can simply write:

                  execute_update(string_table('foo','bar','baz'), 32);
                  

                  我假设您可以从 C# 以编程方式构建此命令.

                  I'm assuming that you can handle building up this command programatically from C#.

                  顺便说一句,在我的公司,我们将许多自定义类型定义为字符串、双精度、整数等列表的标准.我们还利用 Oracle JPublisher 能够直接从这些类型映射到相应的 Java 对象.我快速浏览了一下,但看不到 C# 的任何直接等价物.只是想我会提到它以防 Java 开发人员遇到这个问题.

                  As an aside, at my company we have a number of these custom types defined as standard for lists of strings, doubles, ints and so on. We also make use of Oracle JPublisher to be able to map directly from these types into corresponding Java objects. I had a quick look around but I couldn't see any direct equivalents for C#. Just thought I'd mention it in case Java devs come across this question.

                  这篇关于带有 IN 子句参数的 Oracle 存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:oracle -- 将oracle表中的多个逗号分隔值拆分为多行 下一篇:Oracle 相当于 MySQL INSERT IGNORE?

                  相关文章

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

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

                      <tfoot id='F2smu'></tfoot>