0
1.對於下面的代碼,我沒有得到任何輸出。執行此代碼後DBMS輸出窗口什麼也沒有顯示。可能是什麼問題呢? 2.我試過只通過引用屬性[@ id =「1」]來獲取一個名稱,是否可以獲取所有名稱?如何在pl sql中使用XMLTABLE執行XSL轉換?
declare
x varchar(100);
c1 sys_refcursor;
xml clob:=
'<?xml version="1.0"?>
<Com>
<Employee id="1">
<Name>John</Name>
<Age>21</Age>
<Phone>111111111</Phone>
</Employee>
<Employee id="2">
<Name>Adam</Name>
<Age>22</Age>
<Phone>22222222</Phone>
</Employee>
<Employee id="3">
<Name>David</Name>
<Age>22</Age>
<Phone>333333333</Phone>
</Employee>
<Employee id="4">
<Name>Roy</Name>
<Age>22</Age>
<Phone>44444444</Phone>
</Employee>
</Com>';
xsl clob:=
'<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="Com/Employee[@id=''1'']">
<![CDATA[<Com>]]>
<xsl:value-of select="Name"/>
<![CDATA[</Com>]]>
</xsl:for-each>
</xsl:template>
</xsl:transform>';
function fun1 return sys_refcursor
as
c2 sys_refcursor;
begin
open c2 for select Names_List from XMLTABLE('/Com/Employee'
PASSING XMLTYPE(XMLTRANSFORM(xmltype(xml),xmltype(xsl)).GetClobVal())
columns Names_List varchar(100) path 'Name');
return c2;
end;
begin
c1:=fun1;
loop
fetch c1 into x;
exit when c1%notfound;
dbms_output.put_line('Names : '|| x);
end loop;
end;
只是刪除'[@id =''1'']'然後看。 –