|
List Info
Thread: Re: xmltable question
|
|
| Re: xmltable question |
  United States |
2008-08-27 14:10:38 |
|
Try using a connect by prior in the sql statement.
--- On Wed, 8/27/08, David Wendelken <david_wendelken nc.rr.com> wrote:
From: David Wendelken <david_wendelken nc.rr.com> Subject: xmltable question To: "Multiple recipients of list ODTUG-SQLPLUS-L" <ODTUG-SQLPLUS-L fatcity.com> Date: Wednesday, August 27, 2008, 9:00 AM
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:
set serveroutput on size 1000000
declare
v_xml_folders xmltype :=
'<reports>
<folder key="1">
<folder key="1.1" />
<folder key="1.2" />
</folder>
<folder key="2" />
</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.' |
|
[1]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|