Splitting comma separated string in a PL/SQL stored proc

前端 未结 8 1819
别跟我提以往
别跟我提以往 2020-11-30 05:08

I\'ve CSV string 100.01,200.02,300.03 which I need to pass to a PL/SQL stored procedure in Oracle. Inside the proc,I need to insert these values in a Number column in the ta

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 05:44

    create or replace procedure pro_ss(v_str varchar2) as
    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);   
        if  v_comma_pos = 0 then     
          v_str1 := substr(v_str,v_start_pos);  
          dbms_output.put_line(v_str1);    
          exit;
          end if;    
        v_str1 := substr(v_str,v_start_pos,(v_comma_pos - v_start_pos)); 
        dbms_output.put_line(v_str1);       
        v_start_pos := v_comma_pos + 1;    
        end loop; 
    end;
    /
    
    call pro_ss('aa,bb,cc,dd,ee,ff,gg,hh,ii,jj');
    

    outout: aa bb cc dd ee ff gg hh ii jj

提交回复
热议问题