以下是我从网上获取的程序。但在执行时给出了错误“必须声明xmlgen.setRowsetTag”
请告诉我这个错误是由于某些设置错误还是我必须包含一些文件.. 我正在使用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;
答案 0 :(得分:3)
从Das 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;
/
并且lo!
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。