sql - take values from a string of characters separated from comma -
i have string :
[ quotazioni in euro riferite al 08/08/2017 "" paese,valuta,codice iso,codice uic,quotazione,convenzione di cambio,nota "" afghanistan,afghani,afn,115,80.8402,quantità di valuta per 1 euro albania,lek,all,047,132.275,quantità di valuta per 1 ] i wanna start sixth line , insert variable 'country' afghanistan , albania , variable 'id' afn , all. how can in pl sql?
declare v_string varchar2 (4000) := '[ quotazioni in euro riferite al 08/08/2017 "" paese,valuta,codice iso,codice uic,quotazione,convenzione di cambio,nota "" afghanistan,afghani,afn,115,80.8402,quantità di valuta per 1 euro albania,lek,all,047,132.275,quantità di valuta per 1 ]'; country varchar2 (20); id varchar2 (5); begin row in (select * ( select regexp_substr (line6, '[^,]+', 1, level) fields, row_number () on (order rownum) rn (select regexp_substr (v_string, '^.*$', 1, 5, 'm') line6 dual) connect regexp_substr (v_string, '[^,]+', 1, level) not null) pivot (max (fields) rn in (1 field_1, 2 field_2, 3 field_3, 4 field_4, 5 field_5, 6 field_6))) loop country := row.field_1; id := row.field_3; end loop; end; / your table design not efficient , not data model have here. related records distinct must placed in proper columns , merged single string.
you can achieve shown using regexp_substr split string , pivot convert appropriate fields named columns.
Comments
Post a Comment