2011-05-02 152 views
1

下面是我从拍摄的过程net..but在执行其给我的错误是“xmlgen.setRowsetTag必须声明”读取XML文件

请告诉我,如果这是错误由于一些设置错误或者我必须包括一些文件.. 我使用PL/SQL开发人员10g的

Thankss: -

create or replace procedure SP_XML_TEST is 
begin 
declare 
xmlString CLOB := null; 
-- Here we are reading 250 bytes at a time. We should be really reading a 
-- whole chunk. dbms_output.put_line can only accomodate 256 characters per line 
-- so we have this limitation. 
amount integer:= 255; 
position integer := 1; 
charString varchar2(255); 

begin 

xmlgen.setRowTag('EMP_ROW');      -- we want the row element to be named EMP_ROW. 

xmlgen.setRowsetTag('EMP_RESULTS');  -- we want the result document root to be EMP_RESULTS. 
xmlgen.setMaxRows(3);          -- limit the output to 3 rows. 
xmlgen.setskipRows(2);          -- skip the first two rows in the query before outputing results. 
xmlgen.useLowerCaseTagNames();     -- set the tag names to be all in lower case. 
xmlgen.setErrorTag('ERROR_RESULT');   -- set the ERROR tag to be ERROR_RESULTS. 
xmlgen.setRowIdAttrName('ENO');     -- set the id attribute in the ROW element to be ENO. 
xmlgen.setRowIdColumn('EMPNO');     -- use the EMPNO column's value for the id attribute. 
xmlgen.useNullAttributeIndicator(false);   -- do not use the null indicator to indicate nullness. 
xmlgen.setStyleSheet('http://www.oracle.com/xsl'); -- attach the stylesheet PI to the result document. 

xmlString := xmlgen.getXML('select * from scott.emp ',1); -- This gets the XML out 

dbms_lob.open(xmlString,DBMS_LOB.LOB_READONLY); -- Now open the lob data.. 
loop 
dbms_lob.read(xmlString,amount,position,charString);  -- read the lob data 
dbms_output.put_line(charString); 
position := position + amount; 
end loop; 

exception 
when no_data_found then 
dbms_lob.close(xmlString);             -- end of fetch, free the lob 
dbms_lob.freetemporary(xmlString); 
xmlgen.resetOptions; 
when others then 
xmlgen.resetOptions; 
    end; 


    end SP_XML_TEST; 

回答

3

与达斯Interweb捡东西了的问题是质量控制可能很差。特别是你需要注意版本号。你在使用Oracle 10g。我认为XMLGEN是在XDK for Oracle 8i中引入的;它在9i中不赞成使用PL/SQL包DBMS_XMLGEN,并且(据我所知)在数年内还没有被包含在数据库中。

DBMS_XMLGEN对XMLGEN做类似的事情,虽然有些过程有稍微不同的签名,有些完全被删除。我已将发布的代码重写为使用DBMS_XMLGEN。

create or replace procedure SP_XML_TEST is 
    xmlString CLOB; 
    amount integer:= 255; 
    position integer := 1; 
    charString varchar2(255); 
    len pls_integer; 

    l_ctx dbms_xmlgen.ctxHandle; 

begin 

    l_ctx := dbms_xmlgen.newcontext('select * from apc.emp'); 

    dbms_xmlgen.setRowTag(l_ctx, 'EMP_ROW');      -- we want the row element to be named EMP_ROW. 
    dbms_xmlgen.setRowsetTag(l_ctx, 'EMP_RESULTS');  -- we want the result document root to be EMP_RESULTS. 
    dbms_xmlgen.setMaxRows(l_ctx, 3);          -- limit the output to 3 rows. 
    dbms_xmlgen.setskipRows(l_ctx, 2);          -- skip the first two rows in the query before outputing results. 

    xmlString := dbms_xmlgen.getXML(l_ctx ); -- This gets the XML out 

    dbms_output.put_line('rows read = '||to_char(dbms_xmlgen.GETNUMROWSPROCESSED(l_ctx))); 
    len := dbms_lob.getlength (xmlString); 

    dbms_lob.open(xmlString,DBMS_LOB.LOB_READONLY); -- Now open the lob data.. 
    loop 
     dbms_lob.read(xmlString,amount,position,charString);  -- read the lob data 
     dbms_output.put_line(charString); 
     position := position + amount; 
     EXIT when position > len; 
    end loop; 

    dbms_lob.close(xmlString); 
    dbms_xmlgen.closecontext(l_ctx); 

end SP_XML_TEST; 
/

而且!

SQL> exec SP_XML_TEST 
rows read = 3 
<?xml version="1.0"?> 
<EMP_RESULTS> 
<EMP_ROW> 
    <EMPNO>8085</EMPNO> 

<ENAME>TRICHLER</ENAME> 
    <JOB>PLUMBER</JOB> 
    <MGR>8061</MGR> 

<HIREDATE>08-APR-10</HIREDATE> 
    <SAL>3500</SAL> 
    <DEPTNO>50</DEPTNO> 

</EMP_ROW> 
<EMP_ROW> 
    <EMPNO>7369</EMPNO> 
    < 
ENAME>CLARKE</ENAME> 
    <JOB>CLERK</JOB> 
    <MGR>7902</MGR> 

<HIREDATE>17-DEC-80</HIREDATE> 
    <SAL>800</SAL> 
    <DEPTNO>20</DEPTNO> 

</EMP_ROW> 
<EMP_ROW> 
    <EMPNO>7499</EMPNO> 
    <ENAME>VAN WIJK</ENAME> 

<JOB>SALESMAN</JOB> 
    <MGR>7698</MGR> 
    <HIREDATE>20 
-FEB-81</HIREDATE> 
    <SAL>1600</SAL> 
    <COMM>300</COMM> 
    <DEPTNO>30</DEPTNO> 

</EMP_ROW> 
</EMP_RESULTS> 

顺便说一句,别的东西,因为原来的编码器破解该程序已经改变的是对DBMS_OUTPUT缓冲的限制。在10g中它可以达到32767. Find out more