Purpose
XMLFOREST() constructs a forest of XML elements. It converts each parameter into an XML element, concatenates the elements, and returns an XMLType sequence.
Syntax
XMLFOREST
( value_expr [ AS { c_alias | EVALNAME value_expr } ]
[, value_expr [ AS { c_alias | EVALNAME value_expr } ]
]...
)
Parameters
| Parameter | Description |
|---|---|
| value_expr | The name of the column where the data value to be tagged belongs. |
| AS tag | The name of the tag. If the column name is an expression, the AS tag clause is optional. By default, the tag name is the name of the expression column in uppercase. If the column name is not an expression, such as an aggregate function, a literal, or a concatenation of two columns, the AS tag clause is required. |
| tag | A tag name that complies with the XML naming conventions. The value can be a string. EVALNAME is followed by an expression that evaluates to a string literal. |
Return type
The value is a string of XMLType data concatenated in serial.
Examples
obclient> create table xml_test( n1 NUMBER, n2 NUMBER, c1 VARCHAR2(10), c2 VARCHAR2(10));
obclient> insert into xml_test values(1, 11, 'a', 'bb');
obclient> insert into xml_test values(2, 22, 'c', 'dd');
# Place the `n1` value in the `tag1` element and `n2` value in the `tag2` element, and return the XMLType string of the concatenated elements.
obclient> select xmlforest(n1 as tag2, n2 as tag2) from xml_test;
<TAG1>1</TAG1><TAG2>11</TAG2>
<TAG1>2</TAG1><TAG2>22</TAG2>