分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
165.Oracle数据库SQL开发之 XML和ORACLE——从关系数据生成XML
欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/50186095
ORACLE数据库包含很多SQL函数,使用这些函数可以生成XML。
1. XMLELEMENT()
可以从关系数据生成XML元素。
store@PDB1> selectxmlelement("customer_id",customer_id) as xml_customers fromcustomers;
XML_CUSTOMERS
----------------------------------------------------------------------------------------------------
<customer_id>1</customer_id>
<customer_id>2</customer_id>
<customer_id>3</customer_id>
<customer_id>4</customer_id>
<customer_id>5</customer_id>
2. XMLATTRIBUTES()
可以指定由XMLELEMENT检索的XML元素的属性。
store@PDB1> selectxmlelement("customers",xmlattributes(customer_id as"id",first_name || ' ' ||last_name as "name",
to_char(dob,'MM/DD/YYYY') as "dob")) as xml_customers fromcustomers where customer_id in (1,2)
XML_CUSTOMERS
----------------------------------------------------------------------------------------------------
<customers id="1"name="John Brown" dob="01/01/1965"></customers>
<customers id="2"name="Cynthia Green" dob="02/05/1968"></customers>
3. XMLFOREST()
可以生成XML元素的树形结构。可以将元素连接在一起,而不必使用连接操作符||多次调用XMLELEMENT().
store@PDB1> selectxmlelement("customer",xmlattributes(first_name||' '|| last_name as"name"),
xmlforest(phone as "phone",to_char(dob,'MM/DD/YYYY') as"dob")) as xml_customers from customers where customer_id in (1,2);
XML_CUSTOMERS
----------------------------------------------------------------------------------------------------
<customer name="JohnBrown"><phone>800-555-1211</phone><dob>01/01/1