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

    1. <tfoot id='rGb6Q'></tfoot>

          <bdo id='rGb6Q'></bdo><ul id='rGb6Q'></ul>

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

      1. 在 PL/SQL 中将逗号分隔的字符串转换为数组

        时间:2023-09-19

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

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

                  本文介绍了在 PL/SQL 中将逗号分隔的字符串转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何将逗号分隔的字符串转换为数组?

                  How do I convert a comma separated string to a array?

                  我有输入 '1,2,3' ,我需要把它转换成一个数组.

                  I have the input '1,2,3' , and I need to convert it into an array.

                  推荐答案

                  Oracle 提供了内置函数 DBMS_UTILITY.COMMA_TO_TABLE.

                  Oracle provides the builtin function DBMS_UTILITY.COMMA_TO_TABLE.

                  不幸的是,这个不适用于数字:

                  Unfortunately, this one doesn't work with numbers:

                  SQL> declare
                    2    l_input varchar2(4000) := '1,2,3';
                    3    l_count binary_integer;
                    4    l_array dbms_utility.lname_array;
                    5  begin
                    6    dbms_utility.comma_to_table
                    7    ( list   => l_input
                    8    , tablen => l_count
                    9    , tab    => l_array
                   10    );
                   11    dbms_output.put_line(l_count);
                   12    for i in 1 .. l_count
                   13    loop
                   14      dbms_output.put_line
                   15      ( 'Element ' || to_char(i) ||
                   16        ' of array contains: ' ||
                   17        l_array(i)
                   18      );
                   19    end loop;
                   20  end;
                   21  /
                  declare
                  *
                  ERROR at line 1:
                  ORA-00931: missing identifier
                  ORA-06512: at "SYS.DBMS_UTILITY", line 132
                  ORA-06512: at "SYS.DBMS_UTILITY", line 164
                  ORA-06512: at "SYS.DBMS_UTILITY", line 218
                  ORA-06512: at line 6
                  

                  但是有一个小技巧,用'x'前缀元素,它的工作原理:

                  But with a little trick to prefix the elements with an 'x', it works:

                  SQL> declare
                    2    l_input varchar2(4000) := '1,2,3';
                    3    l_count binary_integer;
                    4    l_array dbms_utility.lname_array;
                    5  begin
                    6    dbms_utility.comma_to_table
                    7    ( list   => regexp_replace(l_input,'(^|,)','1x')
                    8    , tablen => l_count
                    9    , tab    => l_array
                   10    );
                   11    dbms_output.put_line(l_count);
                   12    for i in 1 .. l_count
                   13    loop
                   14      dbms_output.put_line
                   15      ( 'Element ' || to_char(i) ||
                   16        ' of array contains: ' ||
                   17        substr(l_array(i),2)
                   18      );
                   19    end loop;
                   20  end;
                   21  /
                  3
                  Element 1 of array contains: 1
                  Element 2 of array contains: 2
                  Element 3 of array contains: 3
                  
                  PL/SQL procedure successfully completed.
                  

                  问候,罗布.

                  这篇关于在 PL/SQL 中将逗号分隔的字符串转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从存储过程返回多行?(Oracle PL/SQL) 下一篇:如何在 SELECT 语句中使用 BOOLEAN 类型

                  相关文章

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

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