Loop through XMLType
752479Apr 28 2011 — edited Apr 28 2011Hi ALL,
I m trying to loop through an XML message in plsql to parse it:
xml ="<PERSON> <NAME ike="uno"> ramesh </NAME> <NAME
ike="duo"> foo </NAME> </PERSON>"
I m using the following procedure but I m getting only one value ('ramesh ').I want to get each value in a line so I can insert them in a varray .
declare
var XMLType;
var2 XMLType;
buf varchar2(2000);
type refcur is ref cursor;
rc refcur;
begin
var := xmltype('<PERSON> <NAME ike="uno"> ramesh </NAME> <NAME
ike="duo"> foo </NAME> </PERSON>');
var2 := var.extract( '/PERSON/NAME[@ike="uno"]' );
dbms_output.put_line( 'hello' );
OPEN rc FOR
SELECT extract(value(xooty), '//NAME[1]/text()').getStringVal() AS empno
FROM table(xmlsequence(extract(var, '/PERSON'))) xooty;
LOOP
fetch rc into buf;
exit when rc%notfound;
dbms_output.put_line( buf );
END LOOP;
end;
output:
hello
ramesh
The desired output is :
hello
ramesh
foo
BR
Enna