1)函数的作用:
You use SQL/XML standard function XMLSerialize to obtain a string or LOB
representation of XML data.
2)函数语法结构:
看图:
语法说明:
value_expr:Argument value_expr is evaluated, and the resulting XMLType instance is serialized
to produce the content of the created string or LOB. If present 1 , the specified
datatype must be one of the following (the default data type is CLOB):
VARCHAR2(N), where N is the size in bytes (limit 4000)
CLOB
BLOB
DOCUMENT OR CONTENT: If you specify DOCUMENT, then the result of evaluating value_expr must be a
well-formed document. In particular, it must have a single root. If the result is not a
well-formed document, then an error is raised. If you specify CONTENT, however, then
the result of value_expr is not checked for being well-formed.
ENCODING: The ENCODING clause specifies the character encoding for XML data that is serialized
as a BLOB instance. xml_encoding_spec is an XML encoding declaration
(encoding="..."). If datatype is BLOB and you specify an ENCODING clause, then
the output is encoded as specified, and xml_encoding_spec is added to the prolog
to indicate the BLOB encoding. If you specify an ENCODING clause with a datatype
other than BLOB, then an error is raised.
HIDE DEFAULTS and SHOW DEFAULTS: HIDE DEFAULTS and SHOW DEFAULTS apply only to XML schema-based data. If you
specify SHOW DEFAULTS and the input data is missing any optional elements or
attributes for which the XML schema defines default values, then those elements or
attributes are included in the output with their default values. If you specify HIDE
DEFAULTS, then no such elements or attributes are included in the output. HIDE
DEFAULTS is the default behavior.
3) 例子:
a) SELECT XMLSerialize(DOCUMENT XMLType('<poid>143598</poid>') AS CLOB)
AS xmlserialize_doc FROM DUAL;
b) select xmlserialize(DOCUMENT xmltype('<?xml version="1.0" encoding="ISO-8859-15"?><rss version="2.0"><channel><title>Test</title></channel></rss>')) from dual;
c) SQL> select XMLSerialize
2 (
3 CONTENT
4 XMLElement
5 (
6 "XMLDetails",
7 XMLElement("Source",'ORACLE'),
8 XMLElement("Destination",'WEBSERVICE'),
9 XMLElement
10 (
11 "OrderRef",
12 XMLElement
13 (
14 "OrderNo",
15 XMLAttributes('1234' as "Id"),
16 'xyz'
17 ),
18 XMLElement("OrderDate",'7169')
19 ),
20 XMLElement("MessageType",'Success')
21 )
22 as CLOB indent size = 2
23 )
24 from dual
25 /
4) 参考资料列表:
a) PDF:Oracle XML DB Developer's Guide 11g R2
b) http://download.oracle.com/javadb/10.5.3.0/ref/rreffuncxmlserialize.html
c) http://www.oradev.com/xml_functions.jsp
d) http://forums.oracle.com/forums/thread.jspa?threadID=775817
e) http://forums.oracle.com/forums/thread.jspa?messageID=2303661�
f) http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0511melnyk/