--XmlElement multiple label levelsSELECTXMLELEMENT ("TEST", XMLELEMENT ("AA", XMLELEMENT ("BB" ,'XXX'), XMLELEMENT ("CC",'XXX'))) fromDUAL; SELECTXMLELEMENT ("test") fromDUAL----xmlattributes Multiple PropertiesSELECTXMLELEMENT ("TEST",'123', XMLELEMENT ("AA", XmlAttributes ('1235678'" Test_attribute"), XMLELEMENT ("BB", XmlAttributes ( 'Z'"Attr",NULL"XO"),'XXX'), XMLELEMENT ("CC",'XXX')), 'qwe') fromDUAL; --Xmlforest, if you want to define a label node property value, you cannot use theSELECTXMLELEMENT ("TEST", Xmlforest (NULL"WW",'1'"XX",'3'"XX")) fromdual;--about whether a null value produces a label that should be born--1, XmlElement null or NULL will have the end of the label does not appear </>, xmlattributes null value or null corresponding key name does not appear SELECTXMLELEMENT ("Test", XMLELEMENT ("Test1", XmlAttributes (1"Test1_attribute"),NULL), XMLELEMENT ("Test2", XmlAttributes ("'"Test2_attribute"),"'), XMLELEMENT ("Test3", XmlAttributes (NULL"Test3_attribute")),'haha') fromdual;--2.xmlforest NULL The entire label name does not appear, and single quotes appearSELECTXMLELEMENT ("Test", Xmlforest (NULL"Test1","'TEST3)) fromdual;--Xmlagg generating XML fragments withT as(SELECT '1'A'A'B fromDual--UNION All Select ' 2 ', ' A ' B from dual UNION all select ' 3 ', ' B ' b from dual--1SELECTXMLELEMENT ("KK", Xmlagg (XMLELEMENT ("TEST", a))) fromTGROUP byb;--2SELECTXMLELEMENT ("TT", (SELECTXmlagg (XMLELEMENT ("TEST", a)ORDER byA fromT)) fromdual;--SortSELECTXMLELEMENT ("KK", Xmlagg (XMLELEMENT ("TEST", a)ORDER byADESC)) fromTGROUP byb;--can generate invalid Xml,xml can only have one root nodeSELECTXmlagg (XMLELEMENT ("TEST", a)) fromT--The following will be an errorSELECTXMLTYPE. Createxml ('<dummy>X</dummy><dummy>y</dummy>') fromdual;--aggregation, alternative to Sys_path_connect_by,listagg withQ as (SELECT 1 KEY,'A'X fromDUALUNION All SELECT 2 KEY,'B'X fromDUALUNION All SELECT 3 KEY,'A'X fromDUALUNION All SELECT 4 KEY,'A'X fromDUAL)--1SELECTX,RTRIM(Xmlagg (XMLELEMENT (E,Key||',')ORDER by Key)) asConcatval fromQGROUP byX;--2SELECTX,RTRIM(Xmlagg (XMLELEMENT (E,KEY || ',')ORDER by KEY) . EXTRACT ('//text ()'), ',') asConcatval fromQGROUP byX
Oracle XML Operations