Purpose
XMLATTRIBUTES is a subexpression of XMLELEMENT, used to specify the attribute set of an XML element.
Syntax
XMLATTRIBUTES
( [ ENTITYESCAPING | NOENTITYESCAPING ]
[ SCHEMACHECK | NOSCHEMACHECK ]
value_expr [ { AS c_alias } | { AS EVALNAME value_expr } ]
[, value_expr [ { AS c_alias } | { AS EVALNAME value_expr } ] ]...
)
Parameters
| Field | Description |
|---|---|
| ENTITYESCAPING|NOENTITYESCAPING | Optional. Whether to force escaping. If not specified, the default is to force escaping (ENTITYESCAPING). |
| SCHEMACHECK|NOSCHEMACHECK | Optional. Whether to perform runtime checks. If not specified, the default is not to perform runtime checks (NOSCHEMACHECK). Currently, runtime checks are not supported. |
| value_expr | Specifies the attribute value generated from the calculated string literal. |
| c_alias | Specifies the generated attribute name, which is a string type. |
| EVALNAME | Specifies the keyword indicating that the following expression, whose calculated result is a string literal, is to be evaluated. |
Return type
As a subclause of XMLELEMENT, XMLATTRIBUTES cannot be used independently and does not have a return type.
Examples
# Create a table named t1 and insert data.
obclient> CREATE TABLE t1(col1 varchar(10));
Query OK, 0 rows affected
obclient> INSERT INTO t1 VALUES('a');
Query OK, 1 row affected
# Generate an attribute named key with the content of col1.
obclient> SELECT XMLELEMENT(emp, XMLATTRIBUTES(col1 as "key")) FROM t1;
+--------------------------------------------+
| XMLELEMENT(EMP,XMLATTRIBUTES(COL1AS"KEY")) |
+--------------------------------------------+
| <EMP key="a"/>
|
+--------------------------------------------+
1 row in set