Here are some snippets of code showing how to accomplish this:
This first example creates a table with only two columns: id and person. The first is the PK of the table and the second is of XMLType type. The latter is going to contain our XML data.
Now let’s insert one row in the table.
Where you must replace
XMLString with any string representing XML. For example, you can replace it with:
1 2 3 4 5 6 7
I decided to decode the date of birth that way in order to show you (in the next example) how to retrieve, apart from a common XML node, an attribute as well.
1 2 3
This last example extracts the surname and the year of birth from the XML data represented by the person column that is of XMLType type. As you can see to extract the XML data you use regular XPath expressions.
Note: If your XML is using a namespace you will have to indicate it using the following syntax:
XPath_Expression is the XPath expression used to extract the value you’re interested in and
the URI indicating your namespace.
One last note: You can use XML Data inside an Oracle DB from version 9.0.2 on.