将XML输出到文件

时间:2018-02-15 14:15:54

标签: sql xml plsql

我是XML和SQL程序的新手,我试图将其输出到我们的UNIX服务器上的.txt(或.xml?)。我一直在网上看各种各样的东西,但很难做到正确。有人会把我推向正确的方向吗?

create or replace procedure markviewimport_interface (p_invoice_id number(10), p_filename nvarchar(30))
is
    v_output clob;

begin

SELECT  
            XMLFOREST(
                XMLCONCAT(
                        XMLELEMENT("CREATEDBY",XMLATTRIBUTES('Exported By' AS "header"), 'Magellan IT'),
                        XMLELEMENT("TIMESTAMP",XMLATTRIBUTES('Date' AS "header"), TO_CHAR(SYSDATE,'MM.DD.YYYY')),
                        XMLFOREST(
                            XMLFOREST(
                                XMLFOREST(
                                    'invoice_id' AS "DBFIELD",
                                    'Invoice ID' AS "CAPTION",
                                    r_markviewimport.invoice_id AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'vendor_num' AS "DBFIELD",
                                    'Vendor Num' AS "CAPTION",
                                    r_markviewimport.vendor_num AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'vendor_name' AS "DBFIELD",
                                    'Vendor Name' AS "CAPTION",
                                    r_markviewimport.vendor_name AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'po_number' AS "DBFIELD",
                                    'PO Number' AS "CAPTION",
                                    r_markviewimport.po_number AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'invoice_date' AS "DBFIELD",
                                    'Invoice Date' AS "CAPTION",
                                    r_markviewimport.invoice_date AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'invoice_num' AS "DBFIELD",
                                    'Invoice Number' AS "CAPTION",
                                    r_markviewimport.invoice_num AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'terms_name' AS "DBFIELD",
                                    'Terms Date' AS "CAPTION",
                                    r_markviewimport.terms_name AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'invoice_amount' AS "DBFIELD",
                                    'Invoice Amount' AS "CAPTION",
                                    r_markviewimport.invoice_amount AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'amount_applicable_to_discount' AS "DBFIELD",
                                    'Amount Applicable to Discount' AS "CAPTION",
                                    r_markviewimport.amount_applicable_to_discount AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'amount_paid' AS "DBFIELD",
                                    'Amount Paid' AS "CAPTION",
                                    r_markviewimport.amount_paid AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'payment_date' AS "DBFIELD",
                                    'Payment Date' AS "CAPTION",
                                    r_markviewimport.payment_date AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'filename' AS "DBFIELD",
                                    'File Name' AS "CAPTION",
                                    r_markviewimport.filename AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'complete_filename' AS "DBFIELD",
                                    'Complete File Name' AS "CAPTION",
                                    r_markviewimport.complete_filename AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'document_id' AS "DBFIELD",
                                    'Document ID' AS "CAPTION",
                                    r_markviewimport.document_id AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'text' AS "DBFIELD",
                                    'Text' AS "CAPTION",
                                    r_markviewimport.text AS "VALUE"
                                ) AS "DATA_ITEM",
                                XMLFOREST(
                                    'tool_name' AS "DBFIELD",
                                    'Tool Name' AS "CAPTION",
                                    r_markviewimport.tool_name AS "VALUE"
                                ) AS "DATA_ITEM"
                            ) AS "BASICDATA"
                        )       
                    ) AS "DATA_ROOT"
                ) .getclobval() into v_output  
FROM             
( 
SELECT DISTINCT inv.invoice_id, 
                    vendor.segment1 vendor_num, 
                    vendor.vendor_name, 
                    poh.segment1 po_number, 
                    inv.invoice_date, 
                    inv.invoice_num, 
                    terms.name terms_name, 
                    inv.invoice_amount, 
                    inv.amount_applicable_to_discount, 
                    inv.amount_paid, 
                    pmt.check_date payment_date, 
                    path.filename, 
                    path.complete_filename, 
                    path.document_id, 
                    stamps.text, 
                    stamps.tool_name 
    FROM            apps.ap_invoices_all inv, 
                    apps.ap_invoice_distributions_all dist, 
                    apps.po_distributions_all podi, 
                    apps.ap_invoice_payment_history_v pmt, 
                    apps.fnd_attached_docs_form_vl fnd, 
                    markview.mv_page_image_paths path, 
                    apps.po_vendors vendor, 
                    apps.po_headers_all poh, 
                    apps.ap_terms terms, 
                    ( 
                           SELECT mp.document_id, 
                                  moi.markup_object_id, 
                                  moi.page_markups_view_id, 
                                  moi.text, 
                                  mvt.tool_name, 
                                  mp.page_id 
                           FROM   markview.mv_markup_object moi, 
                                  markview.mv_tool mvt, 
                                  markview.mv_page_markups_view mpmv, 
                                  markview.mv_page mp 
                           WHERE  moi.tool_id = mvt.tool_id 
                           AND    mp.page_id = mpmv.page_id 
                           AND    mpmv.page_markups_view_id = moi.page_markups_view_id 
                           AND    mvt.tool_id IN 
                                  ( 
                                         SELECT mvt.tool_id 
                                         FROM   markview.mv_tool 
                                         WHERE  mvt.tool_name IN ( 'Green Text', 
                                                                  'Blue Sticky Note' ) )) stamps
    WHERE           inv.invoice_id = to_number(fnd.pk1_value) 
    AND             inv.invoice_id = dist.invoice_id 
    AND             poh.po_header_id(+) = podi.po_header_id 
    AND             podi.po_distribution_id(+) = dist.po_distribution_id 
    AND             fnd.file_name = to_char(path.document_id) 
    AND             inv.invoice_id = pmt.invoice_id 
    AND             path.document_id = stamps.document_id(+) 
    AND             path.page_id = stamps.page_id(+) 
    AND             fnd.category_description = 'MarkView Document' 
    AND             fnd.entity_name = 'AP_INVOICES' 
    AND             inv.vendor_id = poh.vendor_id(+) 
    AND             inv.terms_id = terms.term_id 
    AND             inv.vendor_id = vendor.vendor_id 
    AND             path.platform_name = 'UNIX_FS_TO_DOC_SERVER' 
    AND             pmt.void = 'N'
    --AND inv.invoice_id = 4796324

DBMS_XSLPROCESSOR.clob2file(v_output, 'My Directory', 'output.xml');
) r_markviewimport

这是我的程序,我哪里错了? 谢谢!

0 个答案:

没有答案