<small id='3Omin'></small><noframes id='3Omin'>

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

    <legend id='3Omin'><style id='3Omin'><dir id='3Omin'><q id='3Omin'></q></dir></style></legend>

      1. PL/SQL 中是否有拆分字符串的函数?

        时间:2023-09-20
        • <bdo id='HQBay'></bdo><ul id='HQBay'></ul>
            <tbody id='HQBay'></tbody>
        • <tfoot id='HQBay'></tfoot>

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

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

                  本文介绍了PL/SQL 中是否有拆分字符串的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要编写一个过程来规范化具有多个由一个字符连接的标记的记录.我需要获取分割字符串的这些标记,并将每个标记作为新记录插入表中.Oracle 是否有类似拆分"功能的功能?

                  I need to write a procedure to normalize a record that have multiple tokens concatenated by one char. I need to obtain these tokens splitting the string and insert each one as a new record in a table. Does Oracle have something like a "split" function?

                  推荐答案

                  你必须自己动手.例如,

                  You have to roll your own. E.g.,

                  /* from :http://www.builderau.com.au/architect/database/soa/Create-functions-to-join-and-split-strings-in-Oracle/0,339024547,339129882,00.htm
                  
                  select split('foo,bar,zoo') from dual;
                  select * from table(split('foo,bar,zoo'));
                  
                  pipelined function is SQL only (no PL/SQL !)
                  */
                  
                  create or replace type split_tbl as table of varchar2(32767);
                  /
                  show errors
                  
                  create or replace function split
                  (
                      p_list varchar2,
                      p_del varchar2 := ','
                  ) return split_tbl pipelined
                  is
                      l_idx    pls_integer;
                      l_list    varchar2(32767) := p_list;
                      l_value    varchar2(32767);
                  begin
                      loop
                          l_idx := instr(l_list,p_del);
                          if l_idx > 0 then
                              pipe row(substr(l_list,1,l_idx-1));
                              l_list := substr(l_list,l_idx+length(p_del));
                  
                          else
                              pipe row(l_list);
                              exit;
                          end if;
                      end loop;
                      return;
                  end split;
                  /
                  show errors;
                  
                  /* An own implementation. */
                  
                  create or replace function split2(
                    list in varchar2,
                    delimiter in varchar2 default ','
                  ) return split_tbl as
                    splitted split_tbl := split_tbl();
                    i pls_integer := 0;
                    list_ varchar2(32767) := list;
                  begin
                    loop
                      i := instr(list_, delimiter);
                      if i > 0 then
                        splitted.extend(1);
                        splitted(splitted.last) := substr(list_, 1, i - 1);
                        list_ := substr(list_, i + length(delimiter));
                      else
                        splitted.extend(1);
                        splitted(splitted.last) := list_;
                        return splitted;
                      end if;
                    end loop;
                  end;
                  /
                  show errors
                  
                  declare
                    got split_tbl;
                  
                    procedure print(tbl in split_tbl) as
                    begin
                      for i in tbl.first .. tbl.last loop
                        dbms_output.put_line(i || ' = ' || tbl(i));
                      end loop;
                    end;
                  
                  begin
                    got := split2('foo,bar,zoo');
                    print(got);
                    print(split2('1 2 3 4 5', ' '));
                  end;
                  /
                  

                  这篇关于PL/SQL 中是否有拆分字符串的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:表名周围的引号究竟有什么作用? 下一篇:如何使用“as"关键字为 Oracle 中的表设置别名?

                  相关文章

                    • <bdo id='yiKNh'></bdo><ul id='yiKNh'></ul>
                  1. <small id='yiKNh'></small><noframes id='yiKNh'>

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

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