Had two typos when I copied it. <oops
/>
Here it is again:
I have a simple xml structure.
<reports>
<folder key="1">
<folder
key="1.1" />
<folder
key="1.2" />
</folder>
<folder key="2" />
</reports>
I want to query this back and return a table with two
columns:
folder_key folder_parent_key
1
null
1.1
1
1.2
1
2
null
I can't get it to tell me the parent folder's key value.
Here's my code:
declare
v_xml_folders xmltype :=
xmltype.createxml(
'<reports>
<folderroot>
<folder
key="1">
<folder key="1.1" />
<folder key="1.2" />
</folder>
<folder key="2" />
</folderroot>
</reports>');
cursor folder_list is
select folders.*
from XMLTable
('/reports/*//folder'
passing v_xml_folders
columns
"FOLDER_KEY"
VARCHAR2(100) PATH '/folder/ key'
,"FOLDER_PARENT_KEY" VARCHAR2(100) PATH '/parent::node()/ key'
) folders;
BEGIN
for folder_rec in folder_list
loop
DBMS_OUTPUT.PUT_LINE('key=' || folder_rec.folder_key);
DBMS_OUTPUT.PUT_LINE('par=' || folder_rec.folder_parent_key);
end loop;
END;
/
folder_key folder_parent_key
1
null
1.1
null
1.2
null
2
null
I've tried PATH '../ key' and a host of other variations.
Anyone know how to do this? Forums are down, and the
oracle docs are terrible.'
|