Home > Database > Mysql Tutorial > 使用表函数切割字符串

使用表函数切割字符串

WBOY
Release: 2016-06-07 14:56:25
Original
1071 people have browsed it

无详细内容 无 CREATE OR REPLACE TYPE table_userid is table of varchar2(100); create or replace function get_userid_tab(v_str in varchar2) return table_userid pipelined as v_new_str varchar2(4000); begin if nvl(v_str,null) is not null then v

CREATE OR REPLACE TYPE table_userid is table of varchar2(100); 

create or replace function get_userid_tab(v_str in varchar2) return table_userid pipelined as 

v_new_str varchar2(4000); 

begin 

  if nvl(v_str,null) is not  null then 


    v_new_str:=v_str; 

    while 1=1 loop 

      if instr(v_new_str,',')=0 then 

        pipe row(to_number(v_new_str)); 

        exit; 

      else 

        pipe row(to_number(substr(v_new_str,1,instr(v_new_str,',')-1))); 

        v_new_str:=substr(v_new_str,instr(v_new_str,',')+1); 

      end if; 

    end loop; 

  end if; 

  return; 

end; 

测试: select * from table(get_userid_tab('16,17,18,19,20')); 

结果: 
16 
17 
18 
19 
20 
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template