Convert comma separated string to array in PL/SQL

前端 未结 14 2296
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 03:19

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

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

14条回答
  •  盖世英雄少女心
    2020-11-27 03:59

    A quick search on my BBDD took me to a function called split:

    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;AA 
    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;
    

    I don't know if it'll be of use, but we found it here...

提交回复
热议问题