I need to get all the connected tables data while getting values as xml
Till now I can produce specific table results as below,
Table1
id name rollNo
1 aaa 10
2 bbb 15
Table2
id rollNo div
1 10 a
2 15 b
Query
SELECT XMLElement("table1",
XMLAttributes(t.id, t.name, t.rollno))
AS "RESULT"
FROM table1 t where t.rollno=15
Result
<table1 id="2" name="bbb" rollno="15"></table1>
But this way, I am able to get data for specific table only. I want to get the xml data for all the tables related with parent table by foreign key.
Suppose, here table3 is related with table1 or table 4 is related with table 3, That should also come in generated xml. Basically I am looking for full tree.
Expected result:
<table1 id="2" name="bbb" rollno="15"></table1>
<table2 id="2" rollno="15" div="b"></table2>
<table3.. and so on
You can create a function that combines data dictionary queries to find parent-child relationships and
DBMS_XMLGEN.GETXML
to generate and combine XML.The below function takes a
ROWID
, finds the parent and child table, and generates XML for the relevant rows. There are many assumptions here, and this may take a huge amount of work to get working with real data.Calling the function is easy. The current version doesn't return data in exactly the format you want, you may need to transform the XML.
Here's the sample schema I used to generate the above results. This is a simple schema, with only one parent-child relationship, based on a single column that has the same name in both tables.