Purpose
The XMLFOREST function builds an XML element forest by converting each parameter into an XML element and then concatenating the elements. The function returns an XMLType value.
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 that contains the data value to be marked. |
| AS tag | The name of the tag. If the expression is a column name, the AS clause is optional. The default tag name is the column name in uppercase letters. If the expression is not a column name (for example, an aggregate function, a literal, or the concatenation of two columns), the AS clause is required. |
| tag | The tag name that conforms to the XML naming standard. The tag name can be specified as a string. The result of the expression following the EVALNAME keyword must be a string literal. |
Return value
The return value is the concatenated XMLType value.
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 values of the n1 column in the tag1 element and the values of the n2 column in the tag2 element, and return the concatenated XMLType.
obclient> select xmlforest(n1 as tag2, n2 as tag2) from xml_test;
<TAG1>1</TAG1><TAG2>11</TAG2>
<TAG1>2</TAG1><TAG2>22</TAG2>