XMLFOREST
Syntax
Purpose
XMLForest
converts each of its argument parameters to XML, and then returns an XML fragment that is the concatenation of these converted arguments.
-
If
value_expr
is a scalar expression, then you can omit theAS
clause, and Oracle Database uses the column name as the element name. -
If
value_expr
is an object type or collection, then theAS
clause is mandatory, and Oracle uses the specified expression as the enclosing tag.You can do this by specifying
c_alias
, which is a string literal, or by specifyingEVALNAME
value_expr
. In the latter case, the value expression is evaluated and the result, which must be a string literal, is used as the identifier. The identifier does not have to be a column name or column reference. It cannot be an expression or null. It can be up to 4000 characters if the initialization parameterMAX_STRING_SIZE
=
STANDARD
, and 32767 characters ifMAX_STRING_SIZE
=
EXTENDED
. See "Extended Data Types" for more information. -
If
value_expr
is null, then no element is created for thatvalue_expr
.
Examples
The following example creates an Emp
element for a subset of employees, with nested employee_id
, last_name
, and salary
elements as the contents of Emp
:
SELECT XMLELEMENT("Emp", XMLFOREST(e.employee_id, e.last_name, e.salary)) "Emp Element" FROM employees e WHERE employee_id = 204; Emp Element ---------------------------------------------------------------- <Emp> <EMPLOYEE_ID>204</EMPLOYEE_ID> <LAST_NAME>Baer</LAST_NAME> <SALARY>10000</SALARY> </Emp>
Refer to the example for XMLCOLATTVAL to compare the output of these two functions.