I know how to read the data from file using utl_file but I am facing an issue with the data below. We can't assume in which position data will come as null. How can we handle this?
Sample data: apple|bat|cat|"dog | dog"||||eee||abc
Expected output:
col1:apple
col2:bat
col3:cat
col4:dog dog
col5:
col6:
col7:
col8:eee
col9:
col10:abc
i have tried below code but it's not handling null values
declare
list varchar2(3500) :='apple|bat|cat|"dog | dog"||||eee||abc';
pattern varchar2(20) := '(" [^"]*"|[^|]+)';
i number:=0;
j number;
f varchar2(3500);
c sys_refcursor;
begin
dbms_output.put_line('Raw list: ' || list);
open c for
select level as col,
trim(regexp_substr(replace(list,'|','|'), pattern, 1, rownum))split
from dual
connect by level <= length(regexp_replace(list, pattern)) + 1;
loop
fetch c into j, f;
exit when c%notfound;
dbms_output.put_line('Column ' || i || ': ' || replace(f, '"'));
i:=i+1;
end loop;
close c;
end;
i am getting below output but i need expected output.
Raw list: apple|bat|cat|"dog|dog"||||eee||abc
Column 0: apple
Column 1: bat
Column 2: cat
Column 3: dog
Column 4: dog
Column 5: eee
Column 6: abc
Column 7:
Column 8:
Column 9:
Column 10: