Convert comma separated string to array in PL/SQL

前端 未结 14 2267
没有蜡笔的小新
没有蜡笔的小新 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:38

    declare 
        v_str varchar2(100) := '1,2,3,4,6,7,8,9,0,';
        v_str1 varchar2(100); 
        v_comma_pos number := 0;    
        v_start_pos number := 1;
    begin             
        loop        
        v_comma_pos := instr(v_str,',',v_start_pos);   
        v_str1 := substr(v_str,v_start_pos,(v_comma_pos - v_start_pos)); 
        dbms_output.put_line(v_str1);     
        if  v_comma_pos = 0 then     
        v_str1 := substr(v_str,v_start_pos);  
        dbms_output.put_line(v_str1);    
        exit;
        end if;    
        v_start_pos := v_comma_pos + 1;  
        if  v_comma_pos = 0 then    
        exit;
        end if;       
        end loop; 
    end;
    

提交回复
热议问题