xmltype常用函数
<Emp ID="7839" ENAME="KING"/>
<Emp ID="7934" ENAME="MILLER"/>
2.14 XMLFOREST(value_expr1[,value_expr2],...)
XMLFOREST(value_expr1[,value_expr2],...):该函数用于返回XML块。示例如下:
SQL> SELECT xmlelement ("Employee",xmlforest(ename,sal))
2 FROM emp WHERE empno=7788;
XMLELEMENT ("EMPLOYEE",XMLFOREST(ENAME,SAL))
------------------------------------------------
<Employee>
<ENAME>SCOTT</ENAME>
<SAL>3000</SAL>
</Employee>
2.15 XMLSEQUENCE(xmltype_instance)
XMLSEQUENCE(xmltype_instance):该函数用于返回XMLType实例中顶级节点以下的VARRAY元素。示例如下:
SQL> SELECT xmlsequence(extract(value(x),
2 '/PurchaseOrder/LineItem/*')) varray FROM xmltable x;
VARRAY
--------------------------------------------------
XMLSEQUENCETYPE(XMLTYPE(<LineItem ItemNumber="1">
<Description>The Ruling Class</Description>
<Part Id="715515012423" UnitPrice="29.95" Quantity="2"/>
</LineItem>
), XMLTYPE(<LineItem ItemNumber="2">
<Description>Diabolique</Description>
<Part Id="037429135020" UnitPrice="29.95" Quantity="3"/>
</LineItem>
), XMLTYPE(<LineItem ItemNumber="3">
<Description>8 1/2</Description>
<Part Id="037429135624" UnitPrice="39.95" Quantity="4"/>
</LineItem>
))
2.16 XMLTRANSFORM(xmltype_instance,xsl_ss)
XMLTRANSFORM(xmltype_instance,xsl_ss):该函数用于将XMLType实例按照XSL样式进行转换,并生成新的XMLType实例。示例如下:
SQL> SELECT XMLTRANSFORM(w.warehouse-spec,x.coll).GetClobVal()
2 FROM warehouse w,xsl_tab x
3 WHERE w.warehouse_name='San Francisco';
CREATE TABLE purchase_order( po_no number(9),po_file xmltype)
insert into purchase_order values(68,XMLTYPE('<?xml version="1.0" encoding="UTF-8"?>
<out>?
<record id="1">
<FileName>index.jsp</FileName>
<FileID>1</FileID>
</record>
<record id="2">
<FileName>index2.jsp</FileName>
<FileID>2</FileID>
</record>
</out>'))
SELECT extract(po_file,'out/record/FileName').getStringVal() AS FileName,extract(po_file,'out/record/FileID').getStringVal() AS FileID FROM purchase_order
SELECT extract(po_file,'out/record/@id').getStringVal() AS RECORD FROM purchase_order
SELECT extract(po_file,'out/record/FileName').getStringVal() AS FileName FROM purchase_order
select extractValue(value(i),'/FileName') AS FileName?
from purchase_order x,
table(XMLSequence(extract(x.po_file,'out/record/FileName'))) i
?