Oracle:如何显示 DBMS_XMLDOM.DOMDocument 以进行调试?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4621932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:21:34  来源:igfitidea点击:

Oracle: How do I display DBMS_XMLDOM.DOMDocument for debugging?

oraclexmldom

提问by Peter Goras

Running Oracle 10g, Sqldeveloper 1.5.5

运行 Oracle 10g,Sqldeveloper 1.5.5

I want to view the contents of an DBMS_XMLDOM.DOMDocument as a string in the output or results window in sqldeveloper. or some other simple way to debug this thing...

我想在 sqldeveloper 的输出或结果窗口中以字符串形式查看 DBMS_XMLDOM.DOMDocument 的内容。或者其他一些简单的方法来调试这个东西......

Thanks,P

谢谢,P

回答by Rob van Laarhoven

DBMS_XMLDOM.WRITETOBUFFER  Writes the contents of the node to a buffer.
DBMS_XMLDOM.WRITETOCLOB    Writes the contents of the node to a CLOB.
DBMS_XMLDOM.WRITETOFILE    Writes the contents of the node to a file.

I have PL/SQL code that wites it to the file system using a DIRECTORY:

我有使用目录将它写入文件系统的 PL/SQL 代码:

   dbms_xmldom.writeToFile(dbms_xmldom.newDOMDocument( xmldoc)
                                       ,'DATAPUMPDIR/myfile.xml') ;

I have created a function using dbms_xmldom.writetoclob

我使用 dbms_xmldom.writetoclob 创建了一个函数

   create or replace function xml2clob (xmldoc XMLType) return CLOB is
     clobdoc CLOB := ' ';
   begin
     dbms_xmldom.writeToClob(dbms_xmldom.newDOMDocument( xmldoc)
                                       ,clobdoc) ;
     return clobdoc;
   end;
   /

Query:

询问:

SELECT xml2clob(Sys_Xmlagg(
         Xmlelement(Name "dummy"
                   ,dummy
                   ),Xmlformat('dual')))
   FROM dual;

Output:

输出:

<?xml version="1.0"?>
<dual>
  <dummy>X</dummy>
</dual>

You could try using a function like this:

您可以尝试使用这样的函数:

   create or replace function dom2clob (domdoc  DBMS_XMLDOM.DOMDocument) return CLOB is
     clobdoc CLOB := ' ';
   begin
     dbms_xmldom.writeToClob(domdoc,clobdoc) ;
     return clobdoc;
   end;
   /

回答by 2y's

You can accomplish the same as in:

您可以完成与以下相同的操作:

"SELECT xml2clob(Sys_Xmlagg(Xmlelement(Name "dummy",dummy),Xmlformat('dual'))) FROM dual;" 

with:

和:

SELECT 
    Sys_Xmlagg(Xmlelement(Name "dummy",dummy)
    ,Xmlformat('dual')).Extract('/*').getClobVal()  as "test"
FROM dual; 

and you do not have to create the function "xml2clob"

并且您不必创建函数“xml2clob”

.Extract('/*')is for "pretty printing"

.Extract('/*')是为了“漂亮的印刷”

output:

输出:

<dual>   
  <dummy>X</dummy> 
</dual> 

回答by sweetfa

If you already have an xmltype simply use the function getClobVal()

如果您已经有一个 xmltype,只需使用函数 getClobVal()

xmldoc.getClobVal()

This returns your XMLType as a clob without the additional function overhead.

这将您的 XMLType 作为 clob 返回,而没有额外的函数开销。