The XMLATTRIBUTES function constructs XML attributes from the arguments.

Read syntax diagramSkip visual syntax diagramXMLATTRIBUTES (,attribute-value-expression ASattribute-name)

This function can only be used as an argument of the XMLELEMENT function. The result is an XML sequence containing an XML attribute for each non-null attribute-value-expression argument.

An expression whose result is the attribute value. The data type of attribute-value-expression must not be ROWID, DATALINK, XML or a distinct type that is based on ROWID, DATALINK, or XML. The expression can be any SQL expression. If the expression is not a simple column reference, an attribute name must be specified.
Specifies an attribute name. The name is an SQL identifier that must be in the form of an XML qualified name, or QName. See the W3C XML namespace specifications for more details on valid names. The attribute name cannot be "xmlns" or prefixed with "xmlns:". A namespace is declared using the function XMLNAMESPACES. Duplicate attribute names, whether implicit or explicit, are not allowed.
If attribute-name is not specified, attribute-value-expression must be a column name. The attribute name is created from the column name using the fully escaped mapping from a column name to an XML attribute name.

The result of the function is XML. If the result of any attribute-value-expression can be null, the result can be null; if the result of every attribute-value-expression is null, the result is the null value.


Note: XMLATTRIBUTES does not insert blank spaces or new line characters in the output. All example output has been formatted to enhance readability.
  • Produce an element with attributes.
        NAME "Emp",
         E.EMPNO, E.FIRSTNME ||' '|| E.LASTNAME AS "name"
       AS "Result"
        WHERE E.EDLEVEL = 12
    This query produces the following result:
    EMPNO   Result
    000290  <Emp EMPNO="000290" name="JOHN PARKER"/>
    000310  <Emp EMPNO="000310" name="MAUDE SETRIGHT"/>
    200310  <Emp EMPNO="200310" name="MICHELLE SPRINGER"/>