Purpose
XMLATTRIBUTES is a subexpression of XMLELEMENT that specifies a set of attributes in 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
| Parameter | Description |
|---|---|
| ENTITYESCAPING|NOENTITYESCAPING | Optional. Specifies whether to force escaping. If not specified, ENTITYESCAPING is used by default. |
| SCHEMACHECK|NOSCHEMACHECK | Optional. Specifies whether to perform runtime checks. If not specified, NOSCHEMACHECK is used by default. Currently, runtime checks are not supported. |
| value_expr | Specifies the attribute value generated from the result of the expression. |
| c_alias | Specifies the attribute name, which is a string. |
| EVALNAME | Specifies the keyword that indicates the expression that follows, whose result is a string. |
Return type
XMLATTRIBUTES is a clause of XMLELEMENT and cannot be used independently. Therefore, it has no return type.
Examples
# Create a table named t1 and insert a row of 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