Splitting comma separated string in a PL/SQL stored proc

前端 未结 8 1806
别跟我提以往
别跟我提以往 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:39

    I use apex_util.string_to_table to parse strings, but you can use a different parser if you wish. Then you can insert the data as in this example:

    declare
      myString varchar2(2000) :='0.75, 0.64, 0.56, 0.45';
      myAmount varchar2(2000) :='0.25, 0.5, 0.65, 0.8';
      v_array1 apex_application_global.vc_arr2;
      v_array2 apex_application_global.vc_arr2;
    begin
    
      v_array1 := apex_util.string_to_table(myString, ', ');
      v_array2 := apex_util.string_to_table(myAmount, ', ');
    
      forall i in 1..v_array1.count
         insert into mytable (a, b) values (v_array1(i), v_array2(i));
    end;
    

    Apex_util is available from Oracle 10G onwards. Prior to this it was called htmldb_util and was not installed by default. If you can't use that you could use the string parser I wrote many years ago and posted here.

提交回复
热议问题