Getting error in oracle sql developer trying to print xml

94 Views Asked by At

I am trying to print the following XML as


PLCO_ID is A-006884-2

Trt_numc is 103

Trt_familyc is 1

Trt_days is 2513

Neoadjuvant is 0


PLCO_ID is A-008288-4

Trt_numc is 104

Trt_familyc is 1

Trt_days is 331

Neoadjuvant is 0


Etc. etc.

However, I have been getting an error. I believe my loop is correct as I need to use an implicit cursor for this particular problem. I think I may have to use rpad() in my print to have it print out correctly but I'm not sure. The code is attached below. Thanks in advance for the help!

The XML code is this

enter image description here

enter image description here

1

There are 1 best solutions below

2
On
begin
    for x in (select j.onepatient.extract('//PLCO_ID/text()').getstringval() as PLCO_ID, 
    j.onepatient.extract('//trt_numc/text()').getstringval()as Trt_numc, j.onepatient.extract('//trt_familyc/text()').getstringval() as Trt_familyc, 
    j.onepatient.extract('//trt_days/text()').getstringval() as Trt_days,j.onepatient.extract('//neoadjuvannt/text()').getstringval() as Neoadjuvant 
    from treatment_xml j)
    loop
        dbms_output.put_line('PLCO_ID        is: '||x.PLCO_ID ||chr(10) ||'Trt_numc       is: '||x.Trt_numc ||chr(10) ||
        'Trt_familyc    is: ' || x.Trt_familyc || chr(10) || 'Trt_days       is: ' || x.Trt_days|| chr(10)||
        'Neoadjuvant    is: ' || x.Neoadjuvant || chr(10));
    end  loop;
end;/