Oracle® Database SQL Reference 10g Release 2 (10.2) Part Number B14200-02 |
|
|
View PDF |
Syntax
Purpose
INSERTXMLBEFORE
inserts a user-supplied value into the target XML before the node indicated by the XPath expression. Compare this function with INSERTCHILDXML.
XMLType_instance
is an instance of XMLType
.
The XPath_string
is an Xpath expression indicating one or more nodes into which one or more child nodes are to be inserted. You can specify an absolute XPath_string
with an initial slash or a relative XPath_string
by omitting the initial slash. If you omit the initial slash, the context of the relative path defaults to the root node.
The value_expr
is a fragment of XMLType
that defines one or more nodes being inserted and their position within the parent node. It must resolve to a string.
The optional namespace_string
provides namespace information for the XPath_string
. This parameter must be of type VARCHAR2
.
Examples
The following example is similar to that for INSERTCHILDXML, but it adds a third /Owner
node before the /Owner
node added in the other example. The output of the query has been formatted for readability.
UPDATE warehouses SET warehouse_spec = INSERTXMLBEFORE(warehouse_spec, '/Warehouse/Building/Owner[2]', XMLType('<Owner>ThirdOwner</Owner>')) WHERE warehouse_id = 3; SELECT warehouse_name, EXTRACT(warehouse_spec, '/Warehouse/Building/Owner') "Owners" FROM warehouses WHERE warehouse_id = 3; Name Owners ------------ -------------------------------------------------------------------- New Jersey <Owner>Grandco</Owner> <Owner>ThirdOwner</Owner> <Owner>LesserCo</Owner>