Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Loop through XMLType

752479Apr 28 2011 — edited Apr 28 2011
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 26 2011
Added on Apr 28 2011
2 comments
1,662 views