首页 > 代码库 > oracle xml操作
oracle xml操作
--xmlelement多个标签层级SELECT XMLELEMENT("TEST", XMLELEMENT("AA", XMLELEMENT("BB", ‘XXX‘), XMLELEMENT("CC", ‘XXX‘))) FROM DUAL; SELECT XMLELEMENT("test") FROM DUAL----XMLATTRIBUTES 多个属性SELECT XMLELEMENT("TEST", ‘123‘, XMLELEMENT("AA", XMLATTRIBUTES(‘1235678‘ "test_attribute"), XMLELEMENT("BB", XMLATTRIBUTES(‘z‘ "attr",NULL "XO"), ‘XXX‘), XMLELEMENT("CC", ‘XXX‘)), ‘qwe‘) FROM DUAL; --xmlforest ,如果要定义标签节点属性值则不能用SELECT XMLELEMENT("TEST",XMLFOREST(NULL "WW",‘1‘ "XX",‘3‘ "xx")) FROM dual;--关于空值是否会生成生应的标签--1、xmlelement 空值或null都会有结束的标签不会出现</> ,xmlattributes 空值或null对应的键名不会出现 SELECT XMLELEMENT("test", XMLELEMENT("test1", XMLATTRIBUTES(1 "test1_attribute"),NULL), XMLELEMENT("test2", XMLATTRIBUTES(‘‘ "test2_attribute"),‘‘), XMLELEMENT("test3", XMLATTRIBUTES(NULL "test3_attribute")),‘haha‘) FROM dual;--2.xmlforest null整个标签名不会出现,单引号会出现SELECT XMLELEMENT("test", XMLFOREST(NULL "test1",‘‘ test3)) FROM dual;--xmlagg 生成xml片段WITH t AS (SELECT ‘1‘ a,‘A‘ b FROM dual)-- UNION ALL SELECT ‘2‘,‘A‘ b FROM dual UNION ALL SELECT ‘3‘,‘B‘ b FROM dual)--1SELECT XMLELEMENT("KK",XMLAGG(XMLELEMENT("TEST",a))) FROM t GROUP BY b;--2SELECT XMLELEMENT("TT",(SELECT XMLAGG(XMLELEMENT("TEST",a) ORDER BY a) FROM t)) FROM dual;--排序SELECT XMLELEMENT("KK",XMLAGG(XMLELEMENT("TEST",a) ORDER BY a DESC)) FROM t GROUP BY b;--可生成无效的xml,xml只能有一个根结节点SELECT XMLAGG(XMLELEMENT("TEST",a)) FROM t--以下会报错SELECT XMLTYPE.CreateXML(‘<dummy>X</dummy><dummy>y</dummy>‘) FROM dual;--聚合,可替代 sys_path_connect_by,listaggWITH Q AS (SELECT 1 KEY, ‘A‘ X FROM DUAL UNION ALL SELECT 2 KEY, ‘B‘ X FROM DUAL UNION ALL SELECT 3 KEY, ‘A‘ X FROM DUAL UNION ALL SELECT 4 KEY, ‘A‘ X FROM DUAL)--1 SELECT X,RTRIM(XMLAGG (XMLELEMENT(e, key||‘,‘) ORDER BY key)) AS concatvalFROM qGROUP BY X;--2SELECT X, RTRIM(XMLAGG(XMLELEMENT(E, KEY || ‘,‘) ORDER BY KEY) .EXTRACT(‘//text()‘), ‘,‘) AS CONCATVAL FROM Q GROUP BY X;
oracle xml操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。