UTL_FILE生成空文件

时间:2015-11-03 07:44:21

标签: oracle oracle11g oracle10g oracle-sqldeveloper utl-file

我需要在特定路径中生成.txt文件,我在11i实例中尝试过,它运行正常。但问题是当我尝试添加更多列(仅80列)时,它只生成空文件。当我再次删除一些列时,它工作正常。

我在R12实例中试过它的工作正常并且它产生超过120列作为单行。 相同的代码在11i实例中不起作用,是否需要DBA端的任何设置或11i实例中的任何限制。 任何人都可以帮忙。

2 个答案:

答案 0 :(得分:0)

PROCEDURE xxx_test (    RETCODE IN VARCHAR2,    ERRBUFF IN VARCHAR2) IS
FILENAME  UTL_FILE.FILE_TYPE;
v_file_name varchar2(250);
v_count NUMBER;
CURSOR C1 IS
SELECT  *
FROM
GRC.GR_PO_EDI_TEMP_ARCHIVE GPET
,OE_ORDER_HEADERS_ALL       OOHA
,OE_ORDER_LINES_ALL         OOLA
WHERE GPET.ORDERNUMBER              = OOHA.CUST_PO_NUMBER
AND   OOHA.HEADER_ID                = OOLA.HEADER_ID
AND   OOHA.ORG_ID                   = OOLA.ORG_ID
AND     nvl(GPET.PO_ACK_STATUS,'N') <> 'Y'  ;
i C1%ROWTYPE;   
BEGIN
BEGIN
SELECT 'orders_1.1_'||to_char(sysdate,'yyyymmddHH24MMSS')||'.txt' INTO v_file_name FROM dual;
exception
WHEN others THEN
v_file_name := NULL;
RAISE_APPLICATION_ERROR(-20201,'File Name Generation failed.!!');
END;
FILENAME:= UTL_FILE.FOPEN('/home/outbox',v_file_name,'w',32767);
/* THIS WILL CREATE THE HEADING IN the FILE */
UTL_FILE.PUT_LINE(FILENAME,
'orderNumber' ||'    '||
'orderDate' ||'    '||
'orderType' ||'    '||
'currency' ||'    '||
'paymentTerm' ||'    '||
'paymentTermText' ||'    '||
'customer' ||'    '||
'supplier' ||'    '||
'shipToSite' ||'    '||
'shipFromSite' ||'    '||
'freightTerm' ||'    '||
'freightTermMeaning' ||'    '||
'freightCarrier' ||'    '||
'buyerNotesHeader' ||'    '||
'supplierNotesHeader' ||'    '||
'buyerName' ||'    '||
'buyerEmail' ||'    '||
'buyerContact' ||'    '||
'lineNumber' ||'    '||
'item' ||'    '||
'itemDescriptionFreeForm' ||'    '||
'UOM' ||'    '||
'price' ||'    '||
'quantity' ||'    '||
'reqDeliveryDate' ||'    '||
'supplierSuggestedPrice' ||'    '||
'buyerNotesLines' ||'    '||
'supplierNotesLines' ||'    '||
'lineShippedQuantity' ||'    '||
'lineReceivedQuantity' ||'    '||
'lineBilledQuantity' ||'    '||
'scheduleNum' ||'    '||
'scheduleQuantity' ||'    '||
'scheduleDeliveryDate' ||'    '||
'promisedDeliveryDate' ||'    '||
'quantityPromised' ||'    '||
'buyerNotesSchedule' ||'    '||
'supplierNotesSchdule' ||'    '||
'quantityReceived' ||'    '||
'quantityShipped' ||'    '||
'Action' ||'    '||
'Id' ||'    '||
'shipToSiteName' ||'    '||
'shipToSiteaddress1' ||'    '||
'shipToSiteaddress2' ||'    '||
'shipToSitecity' ||'    '||
'shipToSitestate' ||'    '||
'shipToSitepostalcode' ||'    '||
'shipToSitecountry' ||'    '||
'totallines' ||'    '||
'orderlinesquantitysum' ||'    '||
'scheduleStatus' ||'    '||
'erpHeaderId' ||'    '||
'erpLineId' ||'    '||
'erpScheduleId' ||'    '||
'billToSiteName' ||'    '||
'billToSiteaddress1' ||'    '||
'billToSiteaddress2' ||'    '||                         
'billToSitecity' ||'    '||
'billToSitestate' ||'    '||
'billToSitepostalcode' ||'    '||
'billToSitecountry' ||'    '||
'supplieritemnumber' ||'    '||
'manufacturer' ||'    '||
'flexField1' ||'    '||
'flexField2' ||'    '||
'flexField3' ||'    '||
'flexField4' ||'    '||
'flexField5' ||'    '||
'flexField6' ||'    '||
'flexField7' ||'    '||
'flexField8' ||'    '||
'flexField9' ||'    '||
'flexField10' ||'    '||
'SupplierName' ||'    '||
'LineValue' ||'    '||
'OrderValue' ||'    '||
'customererpitemid' ||'    '||
'suppliererpitemid' ||'    '||
'salesOrder' ||'    '
);
OPEN c1;
loop
fetch c1 INTO i;
exit WHEN c1%notfound;

UTL_FILE.PUT_LINE(FILENAME,
i.ordernumber||'    '||
i.orderdate||'    '||
i.ordertype||'    '||
i.currency||'    '||
i.paymentterm||'    '||
i.paymenttermtext||'    '||
i.customer||'    '||
i.supplier||'    '||
i.shiptosite||'    '||
i.shipfromsite||'    '||
i.freightterm||'    '||
i.freighttermmeaning||'    '||
i.freightcarrier||'    '||
i.buyernotesheader||'    '||
i.suppliernotesheader||'    '||
i.buyername||'    '||
i.buyeremail||'    '||
i.buyercontact||'    '||
i.linenumber||'    '||
i.item||'    '||
i.itemdescriptionfreeform||'    '||
i.uom||'    '||
i.price||'    '||
i.quantity||'    '||
i.reqdeliverydate||'    '||
i.suppliersuggestedprice||'    '||
i.buyernoteslines||'    '||
i.suppliernoteslines||'    '||
i.lineshippedquantity||'    '||
i.linereceivedquantity||'    '||
i.linebilledquantity||'    '||
i.schedulenum||'    '||
i.schedulequantity||'    '||
i.scheduledeliverydate||'    '||
i.promiseddeliverydate||'    '||
i.quantitypromised||'    '||
i.buyernotesschedules||'    '||
i.suppliernotesschdules||'    '||
i.quantityreceived||'    '||
i.quantityshipped||'    '||
i.action||'    '||
i.id||'    '||
i.shiptositename||'    '||
i.shiptositeaddress1||'    '||
i.shiptositeaddress2||'    '||
i.shiptositecity||'    '||
i.shiptositestate||'    '||
i.shiptositepostalcode||'    '||
i.shiptositecountry||'    '||
i.totallines||'    '||
i.orderlinesquantitysum||'    '||
i.schedulestatus||'    '||
i.erpheaderid||'    '||
i.erplineid||'    '||
i.erpscheduleid||'    '||
i.billtositename||'    '||
i.billtositeaddress1||'    '||
i.billtositeaddress2||'    '||
i.billtositecity||'    '||
i.billtositestate||'    '||
i.billtositepostalcode||'    '||
i.billtositecountry||'    '||
i.supplieritemnumber||'    '||
i.manufacturer||'    '||
i.flexfield1||'    '||
i.flexfield2||'    '||
i.flexfield3||'    '||
i.flexfield4||'    '||
i.flexfield5||'    '||
i.flexfield6||'    '||
i.flexfield7||'    '||
i.flexfield8||'    '||
i.flexfield9||'    '||
i.flexfield10||'    '||
i.suppliername||'    '||
i.linevalue||'    '||
i.ordervalue||'    '||
i.customererpitemid||'    '||
i.suppliererpitemid||'    '||
i.salesordernumber||'    '
);
END LOOP;   
UTL_FILE.FCLOSE(FILENAME);
fnd_file.put_line(fnd_file.output,'File created & File Name:  '||v_file_name      );
dbms_output.put_line(v_file_name||' '||'file created '||'for Order Number:   '||i.ordernumber);
exception  
WHEN UTL_FILE.INVALID_PATH THEN
null;
END xxx_test;

答案 1 :(得分:0)

我遇到了同样的问题。

事实证明,这是一个文件大小问题,小于70k,文件将复制正常,但70k或以上,它最终将为0字节。

这不是oracle错误,而是如何挂载共享驱动器。

如果您可以尝试将fcopy用于本地驱动器,您应该会发现它可以正常工作。

让谁负责安装共享驱动器以解决问题。