Purpose
This function serializes XMLType data into the VARCHAR, VARCHAR2, CLOB, or BLOB data type, and supports formatting through parameters.
Syntax
XMLSERIALIZE
( { DOCUMENT | CONTENT } value_expr [ AS datatype ]
[ ENCODING xml_encoding_spec ]
[ VERSION string_literal ]
[ NO INDENT | { INDENT [SIZE = number] } ]
[ { HIDE | SHOW } DEFAULTS ]
)
Parameters
| Parameter | Description |
|---|---|
| DOCUMENT | Specifies the content to be parsed, which must conform to the XML Document specification. |
| CONTENT | Specifies the content to be parsed, which must be a valid XML fragment but does not need to be well-formed. |
| AS datatype | Specifies the return type, which can be defined as VARCHAR, VARCHAR2, BLOB, or CLOB. The default is CLOB. If the return type is BLOB, you can specify ENCODING. |
| ENCODING | Specifies the encoding to use. |
| VERSION | Specifies the version. |
| NO INDENT ELEMENT | Specifies that line breaks and indentation are not added between levels. |
| INDENT SIZE | Specifies the number of spaces for indentation. If set to 0, only line breaks are added between ELEMENT levels, with no indentation. The default value is 2. |
| HIDE | SHOW DEFAULTS | Specifies whether to display the default values defined in the XML schema. |
Return type
Returns data of the VARCHAR, VARCHAR2, CLOB, or BLOB data type.
Examples
obclient> SELECT XMLSERIALIZE(CONTENT XMLPARSE(CONTENT 'aaa' WELLFORMED) AS varchar2(100) VERSION '1.0') AS RES FROM DUAL;
+---------------------------+
| RES |
+---------------------------+
| <?xml version="1.0"?>
aaa |
+---------------------------+
1 row in set
obclient> SELECT XMLSERIALIZE(DOCUMENT XMLPARSE(DOCUMENT '<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<FROM>Jani</FROM>
<heading>Reminder</heading>
<body><p>Do not forget me this weekend!</p></body>
</note>') AS varchar2(200) NO INDENT) AS RES FROM DUAL;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| RES |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| <?xml version="1.0" encoding="UTF-8"?><note><to>Tove</to><FROM>Jani</FROM><heading>Reminder</heading><body><p>Do not forget me this weekend!</p></body></note> |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set
obclient> SELECT XMLSERIALIZE(DOCUMENT XMLPARSE(DOCUMENT '<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<FROM>Jani</FROM>
<heading>Reminder</heading>
<body><p>Do not forget me this weekend!</p></body>
</note>') AS varchar2(200)) AS RES FROM DUAL;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| RES |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| <?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<FROM>Jani</FROM>
<heading>Reminder</heading>
<body>
<p>Do not forget me this weekend!</p>
</body>
</note>
|
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set
