UTL_FILE.IS_OPEN help
Hi,
In report generation procedure,Before opening the file i'm checking like below,But code review put below comment.Please advice me to incorporate this comment..I have confusion on this comment.
IF UTL_FILE.IS_OPEN (v_csv_file) THEN
UTL_FILE.FCLOSE (v_csv_file);
END IF;
v_csv_file := UTL_FILE.FOPEN (v_file_location, v_csv_filename, 'W',32767);
code review comment:
1. UTL_FILE is used to check the file is closed before opening it at the start of both %CSV procs. To me, this is a clear opportunity to encapsulate that check and the exception handling in a separate proc. That way the code to do the opening and handling is written just once and is used more like a service.
Hi BluShadow,
Thanks for reply,
I Was understand the comments, but how i can proceed to implement i have a confusion since whether it should be function /procedure ?
I assume a procedure like below...But it's not working..can you please advice or correct it?
PROCEDURE file_check(p_csv_file UTL_FILE.FILE_TYPE IS
BEGIN
IF close_in AND UTL_FILE.IS_OPEN (p_csv_file) THEN
UTL_FILE.FCLOSE (p_csv_file);
END IF;
Exception
When others then
UTL_FILE.FCLOSE (p_csv_file);
END;
currently my code is like below
v_csv_file UTL_FILE.FILE_TYPE;
v_csv_filename VARCHAR2(70) := 'subject_report_csv_'||i_year||'_'||i_month||'_'||i_school||'.csv';
v_file_location VARCHAR2(50) := 'CAND_RESULTS'; --FOR LIVE
v_data_line VARCHAR2(4000);
BEGIN
-- File maintenance
IF UTL_FILE.IS_OPEN (v_csv_file) THEN
UTL_FILE.FCLOSE (v_csv_file);
END IF;
v_csv_file := UTL_FILE.FOPEN (v_file_location, v_csv_filename, 'W');
Similar Messages
-
Utl_file query help.
hi friends.,
i have oracle client client installed in my machine..
i have used utl file package to write in the text file..but m facing below error.
DECLARE
fid UTL_FILE.FILE_TYPE;
f VARCHAR(200);
v VARCHAR2(32767);
BEGIN
f := 'D:\';-------------------------------------------------------------(My local D drive)
fid := UTL_FILE.FOPEN (f, 'temp.txt', 'W');
UTL_FILE.PUT_LINE (fid, v);
UTL_FILE.FCLOSE (fid);
DBMS_OUTPUT.PUT_LINE ('Successful write to ' || f);
END;
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 449
ORA-29283: invalid file operation
ORA-06512: at line 6Rajnish Chauhan wrote:
hi friends.,
i have oracle client client installed in my machine..
i have used utl file package to write in the text file..but m facing below error.
DECLARE
fid UTL_FILE.FILE_TYPE;
f VARCHAR(200);
v VARCHAR2(32767);
BEGIN
f := 'D:\';-------------------------------------------------------------(My local D drive)
fid := UTL_FILE.FOPEN (f, 'temp.txt', 'W');
UTL_FILE.PUT_LINE (fid, v);
UTL_FILE.FCLOSE (fid);
DBMS_OUTPUT.PUT_LINE ('Successful write to ' || f);
END;
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 449
ORA-29283: invalid file operation
ORA-06512: at line 6
UTL_FILE can access only Server Directory. You need to create a directory object and use it. You can read in detail from the document.
What is your DB Version? -
Need Help: UTL_FILE Reading and Writing to Text File
Hello I am using version 11gR2 using the UTL_FILE function to read from a text file then write the lines where it begins with word 'foo' and end my writing to the text file where the line with the word 'ZEN' is found. Now, I have several lines that begin with 'foo' and 'ZEN' Which make for one full paragraph, and in this paragraph there's a line that begins with 'DE4.2'. Therefore,
I need to write all paragraphs that include the line 'DE4.2' in their beginning and ending lines 'foo' and 'ZEN'
FOR EXAMPLE:
FOO/234E53LLID
THIS IS MY SECOND LINE
THIS IS MY THIRD LINE
DE4.2 THIS IS MY FOURTH LINE
THIS IS MY FIFTH LINE
ZEN/DING3434343
FOO/234E53LLID
THIS IS MY SECOND LINE
THIS IS MY THIRD LINE
THIS IS MY FIFTH LINE
ZEN/DING3434343
I am only interested in writing the first paragraph tha includes line DE4.2 in one of ther lines Not the Second paragraph that does not include the 'DE4.2'
Here's my code thus far:
CREATE OR REPLACE PROCEDURE my_app2 IS
infile utl_file.file_type;
outfile utl_file.file_type;
buffer VARCHAR2(30000);
b_paragraph_started BOOLEAN := FALSE; -- flag to indicate that required paragraph is started
BEGIN
-- open a file to read
infile := utl_file.fopen('TEST_DIR', 'mytst.txt', 'r');
-- open a file to write
outfile := utl_file.fopen('TEST_DIR', 'out.txt', 'w');
-- check file is opened
IF utl_file.is_open(infile)
THEN
-- loop lines in the file
LOOP
BEGIN
utl_file.get_line(infile, buffer);
--BEGINPOINT APPLICATION
IF buffer LIKE 'foo%' THEN
b_paragraph_started := TRUE;
END IF;
--LOOK FOR GRADS APPS
IF b_paragraph_started AND buffer LIKE '%DE4%' THEN
utl_file.put_line(outfile,buffer, FALSE);
END IF;
--ENDPOINT APPLICATION
IF buffer LIKE 'ZEN%' THEN
b_paragraph_started := FALSE;
END IF;
utl_file.fflush(outfile);
EXCEPTION
WHEN no_data_found THEN
EXIT;
END;
END LOOP;
END IF;
utl_file.fclose(infile);
utl_file.fclose(outfile);
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20099, 'Unknown UTL_FILE Error');
END my_app2;
When I run this code I only get one line: DE4.2 I AM MISSING THE ENTIRE PARAGRAPH
PLEASE ADVISE...Hi,
Look at where you're calling utl_file.put_line. The only time you're writing anything is immediately after you find the the key word 'DE4', and then you're writing just that line.
You need to store the entire paragraph, and when you reach the end of the paragraph, write the whole thing only if you found the key word, like this:
CREATE OR REPLACE PROCEDURE my_app2 IS
TYPE line_collection
IS TABLE OF VARCHAR2 (30000)
INDEX BY BINARY_INTEGER;
infile utl_file.file_type;
outfile utl_file.file_type;
input_paragraph line_collection;
input_paragraph_cnt PLS_INTEGER := 0; -- Number of lines stored in input_paragraph
b_paragraph_started BOOLEAN := FALSE; -- flag to indicate that required paragraph is started
found_key_word BOOLEAN := FALSE; -- Does this paragraph contain the magic word?
BEGIN
-- open a file to read
infile := utl_file.fopen('TEST_DIR', 'mytst.txt', 'r');
-- open a file to write
outfile := utl_file.fopen('TEST_DIR', 'out.txt', 'w');
-- check file is opened
IF utl_file.is_open(infile)
THEN
-- loop lines in the file
LOOP
BEGIN
input_paragraph_cnt := input_paragraph_cnt + 1;
utl_file.get_line (infile, input_paragraph (input_paragraph_cnt));
--BEGINPOINT APPLICATION
IF LOWER (input_paragraph (input_paragraph_cnt)) LIKE 'foo%' THEN
b_paragraph_started := TRUE;
END IF;
--LOOK FOR GRADS APPS
IF b_paragraph_started
THEN
IF input_paragraph (input_paragraph_cnt) LIKE '%DE4%'
THEN
found_key_word := TRUE;
END IF;
--ENDPOINT APPLICATION
IF input_paragraph (input_paragraph_cnt) LIKE 'ZEN%' THEN
b_paragraph_started := FALSE;
IF found_key_word
THEN
FOR j IN 1 .. input_paragraph_cnt
LOOP
utl_file.put_line (outfile, input_paragraph (j), FALSE);
END LOOP;
END IF;
found_key_word := FALSE;
input_paragraph_cnt := 0;
END IF;
ELSE -- paragraph is not started
input_paragraph_cnt := 0;
END IF;
EXCEPTION
WHEN no_data_found THEN
EXIT;
END;
END LOOP;
END IF;
utl_file.fclose (infile);
utl_file.fclose (outfile);
--EXCEPTION
-- WHEN OTHERS THEN
-- raise_application_error(-20099, 'Unknown UTL_FILE Error');
END my_app2;
SHOW ERRORSIf you don't have an EXCEPTION section, the default error handling will print an error message, spcifying exactly what the error was, and which line of your code caused the error. By using your own EXCEPTION section, you're hiding all that information. I admit, the error messages aren't always as informative as we'd like, but they're never less informative than "Unknown UTL_FILE Error'. Don't use your own EXCEPTION handling unless you can improve on the default.
Remember that anything inside quotes is case-sensitive. If your file contains upper-case 'FOO', then it won't be "LIKE 'foo%' ".
Edited by: Frank Kulash on Dec 7, 2011 1:35 PM
You may have noticed that this site normally doesn't display multiple spaces in a row.
Whenever you post formatted text (such as your code) on this site, type these 6 characters:
\{code}
(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
Help for debug un package PL/SQL error at line 723 Encountered
create or replace package body SPR_AP_FUSION_EXTRACT_PKG is
PROCEDURE MAIN_FUSION_EXTRACT(
pv_errbuff IN OUT VARCHAR2,
pn_retcode IN OUT NUMBER
IS
lv_ligne VARCHAR2 (500);
lv_rep VARCHAR2 (260); --:= '/usr/tmp';
ln_retcode NUMBER;
vv_separator VARCHAR2 (2) := ';';
ln_compteur_lignes NUMBER := 0; -- nombre de lignes insérées dans le fichier
ln_counteur NUMBER := 0;
vv_buffer VARCHAR2 (32000);
vv_buffer_et VARCHAR2 (32000);
vv_buffer_etold VARCHAR2 (32000);
lt_id UTL_FILE.file_type;
ln_counter NUMBER (24, 0);
lv_seq VARCHAR2 (30);
lv_num_paiement VARCHAR2 (10);
flag_ecriture VARCHAR2 (1);
lv_filler_ligne VARCHAR2 (500);
ln_long_buff NUMBER := 0;
ln_compteur_factures NUMBER := 0;
lv_name VARCHAR2 (500);
vv_entete VARCHAR2 (500);
LV_INVOICE_ID ap_invoices_all.invoice_id%type;
ln_compteur_hold NUMBER := 0;
lv_hode_reason VARCHAR2 (500);
lv_release_reason VARCHAR2 (500);
lv_societe_absorbee VARCHAR2 (500);
lv_societe_absorbante VARCHAR2 (500);
ln_org_id NUMBER := 0;
lv_date_fusion DATE;
err_non_parameter Exception;
err_Soc_sr Exception;
err_file_write Exception;
err_file_invalid_path Exception;
err_ecriture_file Exception;
CURSOR cur_ap_hold_invoices
( LV$invoice_id IN AP_invoices_all.Invoice_Id%TYPE)
IS
SELECT aha.hold_reason, aha.release_reason
from ap_holds_all aha
where aha.invoice_id = LV$invoice_id
rec_ap_hold_invoices cur_ap_hold_invoices%ROWTYPE;
--Enregistrement "DESTINATAIRE"
CURSOR cur_fusion_extract_AP_invoice
( LV$Societe_absorbee IN cgey_parameters.VARCHAR2_VALUE%Type,
LV$Societe_absorbant IN cgey_parameters.VARCHAR2_VALUE%Type,
LV$Date_fusion IN cgey_parameters.DATE_VALUE%Type
IS
SELECT
Aia.Invoice_Id
, Aia.Invoice_Num
, Aia.Invoice_Type_Lookup_Code
, Aia.Invoice_Date
, Pv.Vendor_Id
, Pv.Segment1
, Pv.Vendor_Name
, pvsa.Vendor_Site_Id
, Pvsa.Vendor_Site_Code
, aia.invoice_amount
, aia.amount_paid
-- RG3: Montant repris = valeur restante a regler
, ROUND (NVL(SUM(Apsa.Amount_Remaining),0),2) Amount_Remaining
, Ap_Invoices_Utility_Pkg.get_approval_status(aia.invoice_id,aia.invoice_amount,aia.payment_status_flag,aia.invoice_type_lookup_code) STATUT
, aia.invoice_currency_code
, aia.exchange_rate
, aia.exchange_rate_type
, aia.exchange_date
, Ate.Name Terms_Name
, aia.terms_date
, aia.source
, aia.doc_category_code
, aia.payment_method_lookup_code
, aia.pay_group_lookup_code
, aia.gl_date
, Aia.Doc_Sequence_Id
, aia.accts_pay_code_combination_id
, CGEY_TOOLS_PKG.get_segments_from_ccid(Aia.Accts_Pay_Code_Combination_Id) Cle_Comptable_Founisseur
, aia.org_id
, aia.payment_cross_rate_type
, aia.payment_cross_rate_date
, aia.payment_cross_rate
, aia.payment_currency_code
, aia.attribute_category
, Aia.Attribute1
, Aia.Attribute2
, Aia.Attribute3
, Aia.Attribute4
, Aia.Attribute5
, Aia.Attribute6
, Aia.Attribute7
, Aia.Attribute8
, Aia.Attribute9
, Aia.Attribute10
, Aia.Attribute11
, Aia.Attribute12
, Aia.Attribute13
, Aia.Attribute14
, Aia.Attribute15
, Aia.Global_Attribute_Category
, Aia.Global_Attribute1
, Aia.Global_Attribute2
, Aia.Global_Attribute3
, Aia.Global_Attribute4
, Aia.Global_Attribute5
, Aia.Global_Attribute6
, Aia.Global_Attribute7
, Aia.Global_Attribute8
, Aia.Global_Attribute9
, Aia.Global_Attribute10
, Aia.Global_Attribute11
, Aia.Global_Attribute12
, Aia.Global_Attribute13
, Aia.Global_Attribute14
, Aia.Global_Attribute15
, Aia.Global_Attribute16
, Aia.Global_Attribute17
, Aia.Global_Attribute18
, Aia.Global_Attribute19
, Aia.Global_Attribute20
FROM
Ap_Invoices_All Aia
, Ap_Payment_Schedules_All Apsa
, Po_Vendor_Sites_All Pvsa
, Ap_Terms Ate
, Po_Vendors Pv
WHERE
1=1
-- RG1: Type de la facture
AND Aia.invoice_type_lookup_code IN ('STANDARD', 'CREDIT', 'DEBIT')
AND Apsa.Invoice_Id = Aia.Invoice_Id
AND Pvsa.Vendor_Site_Id = Aia.Vendor_Site_Id
AND Ate.Term_Id = Aia.Terms_Id
AND Pv.Vendor_Id = Aia.Vendor_Id
-- RG 1: pour les factures créées antétieur à la date de fusion
AND Aia.Creation_Date < LV$Date_fusion
-- RG1: Ensemble des lignes de la facture postees
AND NOT EXISTS ( SELECT 'x'
FROM
Ap_Invoice_Distributions_All Aida
WHERE
Aida.Invoice_id = Aia.Invoice_Id
AND NVL(Aida.Accrual_Posted_Flag,'N') <> 'Y' )
-- pour la société absorbée
AND aia.org_id = (select ORGANIZATION_ID from HR_ALL_ORGANIZATION_UNITS HAOU
where HAOU.Name = LV$Societe_absorbee
GROUP BY
Aia.Invoice_Id
, Aia.Invoice_Num
, Aia.Invoice_Type_Lookup_Code
, Aia.Invoice_Date
, Pv.Vendor_Id
, Pv.Segment1
, Pv.Vendor_Name
, pvsa.Vendor_Site_Id
, Pvsa.Vendor_Site_Code
, aia.invoice_amount
, aia.amount_paid
-- RG3: Montant repris = valeur restante a regler
, Apsa.Amount_Remaining
, aia.payment_status_flag
, aia.invoice_currency_code
, aia.exchange_rate
, aia.exchange_rate_type
, aia.exchange_date
, Ate.Name
, aia.terms_date
, aia.source
, aia.doc_category_code
, aia.payment_method_lookup_code
, aia.pay_group_lookup_code
, aia.gl_date
, Aia.Doc_Sequence_Id
, aia.accts_pay_code_combination_id
, aia.org_id
, aia.payment_cross_rate_type
, aia.payment_cross_rate_date
, aia.payment_cross_rate
, aia.payment_currency_code
, aia.attribute_category
, Aia.Attribute1
, Aia.Attribute2
, Aia.Attribute3
, Aia.Attribute4
, Aia.Attribute5
, Aia.Attribute6
, Aia.Attribute7
, Aia.Attribute8
, Aia.Attribute9
, Aia.Attribute10
, Aia.Attribute11
, Aia.Attribute12
, Aia.Attribute13
, Aia.Attribute14
, Aia.Attribute15
, Aia.Global_Attribute_Category
, Aia.Global_Attribute1
, Aia.Global_Attribute2
, Aia.Global_Attribute3
, Aia.Global_Attribute4
, Aia.Global_Attribute5
, Aia.Global_Attribute6
, Aia.Global_Attribute7
, Aia.Global_Attribute8
, Aia.Global_Attribute9
, Aia.Global_Attribute10
, Aia.Global_Attribute11
, Aia.Global_Attribute12
, Aia.Global_Attribute13
, Aia.Global_Attribute14
, Aia.Global_Attribute15
, Aia.Global_Attribute16
, Aia.Global_Attribute17
, Aia.Global_Attribute18
, Aia.Global_Attribute19
, Aia.Global_Attribute20
HAVING NVL(SUM(Apsa.Amount_Remaining),0) <> 0
UNION ALL
SELECT
Aia.Invoice_Id
, Aia.Invoice_Num
, Aia.Invoice_Type_Lookup_Code
, Aia.Invoice_Date
, Pv.Vendor_Id
, Pv.Segment1
, Pv.Vendor_Name
, pvsa.Vendor_Site_Id
, Pvsa.Vendor_Site_Code
, aia.invoice_amount
, aia.amount_paid
-- RG3: Montant repris = valeur restante a regler
, Ap_Invoices_Utility_PKG.get_prepay_amount_remaining (Aia.invoice_Id) "Amount_Remaining"
, Ap_Invoices_Utility_Pkg.get_approval_status(aia.invoice_id,aia.invoice_amount,aia.payment_status_flag,aia.invoice_type_lookup_code) STATUT
, aia.invoice_currency_code
, aia.exchange_rate
, aia.exchange_rate_type
, aia.exchange_date
, Ate.Name Terms_Name
, aia.terms_date
, aia.source
, aia.doc_category_code
, aia.payment_method_lookup_code
, aia.pay_group_lookup_code
, aia.gl_date
, Aia.Doc_Sequence_Id
, aia.accts_pay_code_combination_id
, CGEY_TOOLS_PKG.get_segments_from_ccid(Aia.Accts_Pay_Code_Combination_Id) Cle_Comptable_Founisseur
, aia.org_id
, aia.payment_cross_rate_type
, aia.payment_cross_rate_date
, aia.payment_cross_rate
, aia.payment_currency_code
, aia.attribute_category
, Aia.Attribute1
, Aia.Attribute2
, Aia.Attribute3
, Aia.Attribute4
, Aia.Attribute5
, Aia.Attribute6
, Aia.Attribute7
, Aia.Attribute8
, Aia.Attribute9
, Aia.Attribute10
, Aia.Attribute11
, Aia.Attribute12
, Aia.Attribute13
, Aia.Attribute14
, Aia.Attribute15
, Aia.Global_Attribute_Category
, Aia.Global_Attribute1
, Aia.Global_Attribute2
, Aia.Global_Attribute3
, Aia.Global_Attribute4
, Aia.Global_Attribute5
, Aia.Global_Attribute6
, Aia.Global_Attribute7
, Aia.Global_Attribute8
, Aia.Global_Attribute9
, Aia.Global_Attribute10
, Aia.Global_Attribute11
, Aia.Global_Attribute12
, Aia.Global_Attribute13
, Aia.Global_Attribute14
, Aia.Global_Attribute15
, Aia.Global_Attribute16
, Aia.Global_Attribute17
, Aia.Global_Attribute18
, Aia.Global_Attribute19
, Aia.Global_Attribute20
FROM
Ap_Invoices_All Aia
, Po_Vendor_Sites_All Pvsa
, Ap_Terms Ate
, Po_Vendors Pv
WHERE 1=1
-- RG2: Type de la facture
AND Aia.invoice_type_lookup_code = 'PREPAYMENT'
-- RG2: Amount_Paid <> Invoice_Amount
AND NVL(Aia.Invoice_Amount,0) = NVL(Aia.Amount_Paid,0)
AND Pvsa.Vendor_Site_Id = Aia.Vendor_Site_Id
AND Ate.Term_Id = Aia.Terms_Id
AND Pv.Vendor_Id = Aia.Vendor_Id
-- RG2: Ensemble des lignes de la facture postees
AND NOT EXISTS ( SELECT 'x'
FROM
Ap_Invoice_Distributions_All Aida
WHERE
Aida.Invoice_id = Aia.Invoice_Id
AND NVL(Aida.Accrual_Posted_Flag,'N') <> 'Y' )
-- pour la société absorbée
AND aia.org_id = (select ORGANIZATION_ID from HR_ALL_ORGANIZATION_UNITS HAOU
where HAOU.Name = LV$Societe_absorbee
-- RG 1: pour les factures créées antétieur à la date de fusion
AND Aia.Creation_Date < LV$Date_fusion
GROUP BY
Aia.Invoice_Id
, Aia.Invoice_Num
, Aia.Invoice_Type_Lookup_Code
, Aia.Invoice_Date
, Pv.Vendor_Id
, Pv.Segment1
, Pv.Vendor_Name
, pvsa.Vendor_Site_Id
, Pvsa.Vendor_Site_Code
, aia.invoice_amount
, aia.amount_paid
, aia.payment_status_flag
, aia.invoice_currency_code
, aia.exchange_rate
, aia.exchange_rate_type
, aia.exchange_date
, Ate.Name
, aia.terms_date
, aia.source
, aia.doc_category_code
, aia.payment_method_lookup_code
, aia.pay_group_lookup_code
, aia.gl_date
, Aia.Doc_Sequence_Id
, aia.accts_pay_code_combination_id
, aia.org_id
, aia.payment_cross_rate_type
, aia.payment_cross_rate_date
, aia.payment_cross_rate
, aia.payment_currency_code
, aia.attribute_category
, Aia.Attribute1
, Aia.Attribute2
, Aia.Attribute3
, Aia.Attribute4
, Aia.Attribute5
, Aia.Attribute6
, Aia.Attribute7
, Aia.Attribute8
, Aia.Attribute9
, Aia.Attribute10
, Aia.Attribute11
, Aia.Attribute12
, Aia.Attribute13
, Aia.Attribute14
, Aia.Attribute15
, Aia.Global_Attribute_Category
, Aia.Global_Attribute1
, Aia.Global_Attribute2
, Aia.Global_Attribute3
, Aia.Global_Attribute4
, Aia.Global_Attribute5
, Aia.Global_Attribute6
, Aia.Global_Attribute7
, Aia.Global_Attribute8
, Aia.Global_Attribute9
, Aia.Global_Attribute10
, Aia.Global_Attribute11
, Aia.Global_Attribute12
, Aia.Global_Attribute13
, Aia.Global_Attribute14
, Aia.Global_Attribute15
, Aia.Global_Attribute16
, Aia.Global_Attribute17
, Aia.Global_Attribute18
, Aia.Global_Attribute19
, Aia.Global_Attribute20
HAVING Ap_Invoices_Utility_PKG.get_prepay_amount_remaining (Aia.invoice_Id) <> 0
AND Ap_Invoices_Utility_Pkg.get_approval_status(aia.invoice_id,aia.invoice_amount,aia.payment_status_flag,aia.invoice_type_lookup_code) = 'AVAILABLE'
Rec_fusion_extract_AP_invoice cur_fusion_extract_AP_invoice%ROWTYPE;
BEGIN
---------Initialisation
pn_retcode := 0;
pv_errbuff := NULL;
ln_compteur_lignes := 0;
lv_societe_absorbee := CGEY_TOOLS_PKG.get_varchar2_parameter ('SPR_FUSION_AP_SOCIETE', 'SOC_SR');
lv_societe_absorbante :=CGEY_TOOLS_PKG.get_varchar2_parameter ('SPR_FUSION_AP_SOCIETE', 'SOC_CB');
lv_date_fusion := CGEY_TOOLS_PKG.get_date_parameter ('SPR_FUSION_AP_SOCIETE', 'DATE_FUSION');
lv_rep := cgey_tools_pkg.get_varchar2_parameter ('SPR_FUSION_AP_SOCIETE', 'REPERTOIRE_SORTIE');
----err_non_parameter
IF lv_societe_absorbee is null or lv_societe_absorbante is null or lv_date_fusion is null or lv_rep is null
THEN raise err_non_parameter;
select NVL(ORGANIZATION_ID, 'NULL')
INTO ln_org_id
from HR_ALL_ORGANIZATION_UNITS HAOU
where HAOU.Name = lv_societe_absorbee
----err_Soc_sr
IF ln_org_id ='NULL'
THEN Raise err_Soc_sr;
BEGIN
----Création du fichier sorti
cgey_tools_pkg.put_log_message ('Création et Ouverture du fichier en lecture');
lv_name := 'FUSION_fac_AP_EXTRAIRE' || TO_CHAR(SYSDATE, 'DDMMYYYY_HH24MISS') || '.txt';
cgey_tools_pkg.put_log_message ('Fichier sortie est '|| lv_name );
lt_id := UTL_FILE.FOPEN(lv_rep, lv_name, 'w');
IF UTL_FILE.IS_OPEN(lt_id) THEN
cgey_tools_pkg.put_log_message (cv_line);
cgey_tools_pkg.put_log_message('Creation OK du fichier: ' || lv_name);
ELSE
cgey_tools_pkg.put_log_message(cv_line);
cgey_tools_pkg.put_log_message('Probleme ouverture du fichier ' ||lv_name);
END IF;
----EXCEPTION UTL_FILE.WRITE_ERROR, UTL_FILE.INVALID_PATH
EXCEPTION
WHEN UTL_FILE.WRITE_ERROR
THEN raise err_file_write;
WHEN UTL_FILE.INVALID_PATH
THEN raise err_file_invalid_path;
----Création du fichier sorti
END;
BEGIN
UTL_FILE.PUT_LINE(lt_id, vv_entete);
----CURSOR FACTURE A EXTRAIRE
OPEN cur_fusion_extract_AP_invoice
(lv_societe_absorbee,
lv_societe_absorbante,
lv_date_fusion
LOOP
FETCH cur_fusion_extract_AP_invoice
INTO rec_fusion_extract_AP_invoice;
EXIT WHEN cur_fusion_extract_AP_invoice%NOTFOUND;
LV_INVOICE_ID := rec_fusion_extract_AP_invoice.Invoice_Id;
ln_compteur_hold := 0;
lv_hode_reason := null;
lv_release_reason := null;
OPEN cur_ap_hold_invoices (rec_fusion_extract_AP_invoice.Invoice_Id);
LOOP
FETCH cur_ap_hold_invoices
INTO rec_ap_hold_invoices;
EXIT WHEN cur_ap_hold_invoices%NOTFOUND;
----La première blocage à traiter
IF ln_compteur_hold =0 THEN
lv_hode_reason := nvl(rec_ap_hold_invoices.hold_reason, ' ') ;
lv_release_reason := nvl(rec_ap_hold_invoices.release_reason, ' ');
----concatener des autres blocages suivants pour la même facture
Else
lv_hode_reason := lv_hode_reason||nvl(rec_ap_hold_invoices.hold_reason, ' ');
lv_release_reason := lv_release_reason||nvl(rec_ap_hold_invoices.release_reason, ' ');
END IF;
ln_compteur_hold := ln_compteur_hold +1;
END LOOP;
CLOSE cur_ap_hold_invoices;
vv_buffer :=
NVL(lv_societe_absorbee, ' ') ||vv_separator||
NVL(lv_societe_absorbante, ' ') ||vv_separator||
NVL(to_char(lv_date_fusion,'dd/mm/yyyy' ), ' ') ||vv_separator||
NVL(to_char(rec_fusion_extract_AP_invoice.Invoice_Id), ' ') ||vv_separator
UTL_FILE.PUT_LINE(lt_id, vv_buffer);
ln_compteur_lignes := ln_compteur_lignes + 1;
END LOOP;
cgey_tools_pkg.put_log_message(to_char(ln_compteur_lignes) ||
' lignes inserees dans le fichier ' ||lv_rep||'/'
|| lv_name);
CLOSE cur_fusion_extract_AP_invoice;
UTL_FILE.FCLOSE(lt_id);
cgey_tools_pkg.put_log_message(' ');
cgey_tools_pkg.put_log_message(cv_line);
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
Raise err_ecriture_file;
END ;
EXCEPTION_
WHEN err_non_parameter THEN
pn_retcode := SQLCODE;
cgey_tools_pkg.put_log_message ('error'||SQLCODE);
cgey_tools_pkg.put_log_message ('error parameter : Veuillez vous verifier la configuration dans la table CGEY_PARAMETERS!');
WHEN err_Soc_sr THEN
pn_retcode := SQLCODE;
cgey_tools_pkg.put_log_message ('error'||SQLCODE);
cgey_tools_pkg.put_log_message ('error société_absorbée : Veuillez vous verifier le parameter de la société absorbée !');
WHEN err_file_write THEN
UTL_FILE.FCLOSE(lt_id);
pv_errbuff := SQLERRM;
pn_retcode := SQLCODE;
cgey_tools_pkg.put_log_message ('error'||SQLCODE);
cgey_tools_pkg.put_log_message('erreur write_error:'||pv_errbuff);
WHEN err_file_invalid_path THEN
UTL_FILE.FCLOSE(lt_id);
pn_retcode := SQLCODE;
pv_errbuff := SQLERRM;
cgey_tools_pkg.put_log_message ('error'||SQLCODE);
cgey_tools_pkg.put_log_message('erreur invalid_path:'||pv_errbuff);
WHEN err_ecriture_file THEN
UTL_FILE.FCLOSE(lt_id);
pn_retcode := SQLCODE;
pv_errbuff := SQLERRM;
cgey_tools_pkg.put_log_message ('error'||SQLCODE);
cgey_tools_pkg.put_log_message('err_ecriture_file:'||pv_errbuff);
WHEN OTHERS THEN
cgey_tools_pkg.put_log_message ('Une Erreur inconnue arrive lors que l''extraction du FUSION_fac_AP_EXTRAIRE!!');
END MAIN_FUSION_EXTRACT;
END SPR_AP_FUSION_EXTRACT_PKG;
error at line 723 PLS-100103 "EXCEPTION"
when expecting one of the following Error. Please help me!!
Thanks a lot
Edited by: kinkichin on 11 mars 2010 03:19Hi ,
I have made some changes to the code search for --check condition* and check if the condition is correct.
CREATE OR REPLACE PACKAGE BODY spr_ap_fusion_extract_pkg
IS
PROCEDURE main_fusion_extract (
pv_errbuff IN OUT VARCHAR2,
pn_retcode IN OUT NUMBER
IS
lv_ligne VARCHAR2 (500);
lv_rep VARCHAR2 (260); --:= '/usr/tmp';
ln_retcode NUMBER;
vv_separator VARCHAR2 (2) := ';';
ln_compteur_lignes NUMBER := 0;
-- nombre de lignes insérées dans le fichier
ln_counteur NUMBER := 0;
vv_buffer VARCHAR2 (32000);
vv_buffer_et VARCHAR2 (32000);
vv_buffer_etold VARCHAR2 (32000);
lt_id UTL_FILE.file_type;
ln_counter NUMBER (24, 0);
lv_seq VARCHAR2 (30);
lv_num_paiement VARCHAR2 (10);
flag_ecriture VARCHAR2 (1);
lv_filler_ligne VARCHAR2 (500);
ln_long_buff NUMBER := 0;
ln_compteur_factures NUMBER := 0;
lv_name VARCHAR2 (500);
vv_entete VARCHAR2 (500);
lv_invoice_id ap_invoices_all.invoice_id%TYPE;
ln_compteur_hold NUMBER := 0;
lv_hode_reason VARCHAR2 (500);
lv_release_reason VARCHAR2 (500);
lv_societe_absorbee VARCHAR2 (500);
lv_societe_absorbante VARCHAR2 (500);
ln_org_id NUMBER := 0;
lv_date_fusion DATE;
err_non_parameter EXCEPTION;
err_soc_sr EXCEPTION;
err_file_write EXCEPTION;
err_file_invalid_path EXCEPTION;
err_ecriture_file EXCEPTION;
CURSOR cur_ap_hold_invoices (
lv$invoice_id IN ap_invoices_all.invoice_id%TYPE
IS
SELECT aha.hold_reason, aha.release_reason
FROM ap_holds_all aha
WHERE aha.invoice_id = lv$invoice_id;
rec_ap_hold_invoices cur_ap_hold_invoices%ROWTYPE;
--Enregistrement "DESTINATAIRE"
CURSOR cur_fusion_extract_ap_invoice (
lv$societe_absorbee IN cgey_parameters.varchar2_value%TYPE,
lv$societe_absorbant IN cgey_parameters.varchar2_value%TYPE,
lv$date_fusion IN cgey_parameters.date_value%TYPE
IS
SELECT aia.invoice_id, aia.invoice_num,
aia.invoice_type_lookup_code, aia.invoice_date, pv.vendor_id,
pv.segment1, pv.vendor_name, pvsa.vendor_site_id,
pvsa.vendor_site_code, aia.invoice_amount, aia.amount_paid
-- RG3: Montant repris = valeur restante a regler
ROUND (NVL (SUM (apsa.amount_remaining), 0),
2
) amount_remaining,
ap_invoices_utility_pkg.get_approval_status
(aia.invoice_id,
aia.invoice_amount,
aia.payment_status_flag,
aia.invoice_type_lookup_code
) statut,
aia.invoice_currency_code, aia.exchange_rate,
aia.exchange_rate_type, aia.exchange_date,
ate.NAME terms_name, aia.terms_date, aia.SOURCE,
aia.doc_category_code, aia.payment_method_lookup_code,
aia.pay_group_lookup_code, aia.gl_date, aia.doc_sequence_id,
aia.accts_pay_code_combination_id,
cgey_tools_pkg.get_segments_from_ccid
(aia.accts_pay_code_combination_id
) cle_comptable_founisseur,
aia.org_id, aia.payment_cross_rate_type,
aia.payment_cross_rate_date, aia.payment_cross_rate,
aia.payment_currency_code, aia.attribute_category,
aia.attribute1, aia.attribute2, aia.attribute3,
aia.attribute4, aia.attribute5, aia.attribute6,
aia.attribute7, aia.attribute8, aia.attribute9,
aia.attribute10, aia.attribute11, aia.attribute12,
aia.attribute13, aia.attribute14, aia.attribute15,
aia.global_attribute_category, aia.global_attribute1,
aia.global_attribute2, aia.global_attribute3,
aia.global_attribute4, aia.global_attribute5,
aia.global_attribute6, aia.global_attribute7,
aia.global_attribute8, aia.global_attribute9,
aia.global_attribute10, aia.global_attribute11,
aia.global_attribute12, aia.global_attribute13,
aia.global_attribute14, aia.global_attribute15,
aia.global_attribute16, aia.global_attribute17,
aia.global_attribute18, aia.global_attribute19,
aia.global_attribute20
FROM ap_invoices_all aia,
ap_payment_schedules_all apsa,
po_vendor_sites_all pvsa,
ap_terms ate,
po_vendors pv
WHERE 1 = 1
-- RG1: Type de la facture
AND aia.invoice_type_lookup_code IN
('STANDARD', 'CREDIT', 'DEBIT')
AND apsa.invoice_id = aia.invoice_id
AND pvsa.vendor_site_id = aia.vendor_site_id
AND ate.term_id = aia.terms_id
AND pv.vendor_id = aia.vendor_id
-- RG 1: pour les factures créées antétieur à la date de fusion
AND aia.creation_date < lv$date_fusion
-- RG1: Ensemble des lignes de la facture postees
AND NOT EXISTS (
SELECT 'x'
FROM ap_invoice_distributions_all aida
WHERE aida.invoice_id = aia.invoice_id
AND NVL (aida.accrual_posted_flag, 'N' = 'Y')
--check condition
-- pour la société absorbée
AND aia.org_id =
(SELECT organization_id
FROM hr_all_organization_units haou
WHERE haou.NAME = lv$societe_absorbee)
GROUP BY aia.invoice_id,
aia.invoice_num,
aia.invoice_type_lookup_code,
aia.invoice_date,
pv.vendor_id,
pv.segment1,
pv.vendor_name,
pvsa.vendor_site_id,
pvsa.vendor_site_code,
aia.invoice_amount,
aia.amount_paid
-- RG3: Montant repris = valeur restante a regler
apsa.amount_remaining,
aia.payment_status_flag,
aia.invoice_currency_code,
aia.exchange_rate,
aia.exchange_rate_type,
aia.exchange_date,
ate.NAME,
aia.terms_date,
aia.SOURCE,
aia.doc_category_code,
aia.payment_method_lookup_code,
aia.pay_group_lookup_code,
aia.gl_date,
aia.doc_sequence_id,
aia.accts_pay_code_combination_id,
aia.org_id,
aia.payment_cross_rate_type,
aia.payment_cross_rate_date,
aia.payment_cross_rate,
aia.payment_currency_code,
aia.attribute_category,
aia.attribute1,
aia.attribute2,
aia.attribute3,
aia.attribute4,
aia.attribute5,
aia.attribute6,
aia.attribute7,
aia.attribute8,
aia.attribute9,
aia.attribute10,
aia.attribute11,
aia.attribute12,
aia.attribute13,
aia.attribute14,
aia.attribute15,
aia.global_attribute_category,
aia.global_attribute1,
aia.global_attribute2,
aia.global_attribute3,
aia.global_attribute4,
aia.global_attribute5,
aia.global_attribute6,
aia.global_attribute7,
aia.global_attribute8,
aia.global_attribute9,
aia.global_attribute10,
aia.global_attribute11,
aia.global_attribute12,
aia.global_attribute13,
aia.global_attribute14,
aia.global_attribute15,
aia.global_attribute16,
aia.global_attribute17,
aia.global_attribute18,
aia.global_attribute19,
aia.global_attribute20
HAVING NVL (SUM (apsa.amount_remaining), 0) <>
0
--check condition
UNION ALL
SELECT aia.invoice_id, aia.invoice_num,
aia.invoice_type_lookup_code, aia.invoice_date,
pv.vendor_id, pv.segment1, pv.vendor_name,
pvsa.vendor_site_id, pvsa.vendor_site_code,
aia.invoice_amount, aia.amount_paid
-- RG3: Montant repris = valeur restante a regler
ap_invoices_utility_pkg.get_prepay_amount_remaining
(aia.invoice_id)
"Amount_Remaining",
ap_invoices_utility_pkg.get_approval_status
(aia.invoice_id,
aia.invoice_amount,
aia.payment_status_flag,
aia.invoice_type_lookup_code
) statut,
aia.invoice_currency_code, aia.exchange_rate,
aia.exchange_rate_type, aia.exchange_date,
ate.NAME terms_name, aia.terms_date, aia.SOURCE,
aia.doc_category_code,
aia.payment_method_lookup_code,
aia.pay_group_lookup_code, aia.gl_date,
aia.doc_sequence_id,
aia.accts_pay_code_combination_id,
cgey_tools_pkg.get_segments_from_ccid
(aia.accts_pay_code_combination_id
) cle_comptable_founisseur,
aia.org_id, aia.payment_cross_rate_type,
aia.payment_cross_rate_date,
aia.payment_cross_rate, aia.payment_currency_code,
aia.attribute_category, aia.attribute1,
aia.attribute2, aia.attribute3, aia.attribute4,
aia.attribute5, aia.attribute6, aia.attribute7,
aia.attribute8, aia.attribute9, aia.attribute10,
aia.attribute11, aia.attribute12, aia.attribute13,
aia.attribute14, aia.attribute15,
aia.global_attribute_category,
aia.global_attribute1, aia.global_attribute2,
aia.global_attribute3, aia.global_attribute4,
aia.global_attribute5, aia.global_attribute6,
aia.global_attribute7, aia.global_attribute8,
aia.global_attribute9, aia.global_attribute10,
aia.global_attribute11, aia.global_attribute12,
aia.global_attribute13, aia.global_attribute14,
aia.global_attribute15, aia.global_attribute16,
aia.global_attribute17, aia.global_attribute18,
aia.global_attribute19, aia.global_attribute20
FROM ap_invoices_all aia,
po_vendor_sites_all pvsa,
ap_terms ate,
po_vendors pv
WHERE 1 = 1
-- RG2: Type de la facture
AND aia.invoice_type_lookup_code = 'PREPAYMENT'
-- RG2: Amount_Paid Invoice_Amount
AND NVL (aia.invoice_amount, 0) =
NVL (aia.amount_paid, 0)
AND pvsa.vendor_site_id = aia.vendor_site_id
AND ate.term_id = aia.terms_id
AND pv.vendor_id = aia.vendor_id
-- RG2: Ensemble des lignes de la facture postees
AND NOT EXISTS (
SELECT 'x'
FROM ap_invoice_distributions_all aida
WHERE aida.invoice_id = aia.invoice_id
AND NVL (aida.accrual_posted_flag, 'N') =
'Y')
--check condition
-- pour la société absorbée
AND aia.org_id =
(SELECT organization_id
FROM hr_all_organization_units haou
WHERE haou.NAME = lv$societe_absorbee)
-- RG 1: pour les factures créées antétieur à la date de fusion
AND aia.creation_date < lv$date_fusion
GROUP BY aia.invoice_id,
aia.invoice_num,
aia.invoice_type_lookup_code,
aia.invoice_date,
pv.vendor_id,
pv.segment1,
pv.vendor_name,
pvsa.vendor_site_id,
pvsa.vendor_site_code,
aia.invoice_amount,
aia.amount_paid,
aia.payment_status_flag,
aia.invoice_currency_code,
aia.exchange_rate,
aia.exchange_rate_type,
aia.exchange_date,
ate.NAME,
aia.terms_date,
aia.SOURCE,
aia.doc_category_code,
aia.payment_method_lookup_code,
aia.pay_group_lookup_code,
aia.gl_date,
aia.doc_sequence_id,
aia.accts_pay_code_combination_id,
aia.org_id,
aia.payment_cross_rate_type,
aia.payment_cross_rate_date,
aia.payment_cross_rate,
aia.payment_currency_code,
aia.attribute_category,
aia.attribute1,
aia.attribute2,
aia.attribute3,
aia.attribute4,
aia.attribute5,
aia.attribute6,
aia.attribute7,
aia.attribute8,
aia.attribute9,
aia.attribute10,
aia.attribute11,
aia.attribute12,
aia.attribute13,
aia.attribute14,
aia.attribute15,
aia.global_attribute_category,
aia.global_attribute1,
aia.global_attribute2,
aia.global_attribute3,
aia.global_attribute4,
aia.global_attribute5,
aia.global_attribute6,
aia.global_attribute7,
aia.global_attribute8,
aia.global_attribute9,
aia.global_attribute10,
aia.global_attribute11,
aia.global_attribute12,
aia.global_attribute13,
aia.global_attribute14,
aia.global_attribute15,
aia.global_attribute16,
aia.global_attribute17,
aia.global_attribute18,
aia.global_attribute19,
aia.global_attribute20
HAVING ap_invoices_utility_pkg.get_prepay_amount_remaining
(aia.invoice_id) <>
0
AND ap_invoices_utility_pkg.get_approval_status
(aia.invoice_id,
aia.invoice_amount,
aia.payment_status_flag,
aia.invoice_type_lookup_code
) = 'AVAILABLE');
--check condition;
rec_fusion_extract_ap_invoice cur_fusion_extract_ap_invoice%ROWTYPE;
BEGIN
---------Initialisation
pn_retcode := 0;
pv_errbuff := NULL;
ln_compteur_lignes := 0;
lv_societe_absorbee :=
cgey_tools_pkg.get_varchar2_parameter ('SPR_FUSION_AP_SOCIETE',
'SOC_SR'
lv_societe_absorbante :=
cgey_tools_pkg.get_varchar2_parameter ('SPR_FUSION_AP_SOCIETE',
'SOC_CB'
lv_date_fusion :=
cgey_tools_pkg.get_date_parameter ('SPR_FUSION_AP_SOCIETE',
'DATE_FUSION'
lv_rep :=
cgey_tools_pkg.get_varchar2_parameter ('SPR_FUSION_AP_SOCIETE',
'REPERTOIRE_SORTIE'
----err_non_parameter
IF lv_societe_absorbee IS NULL
OR lv_societe_absorbante IS NULL
OR lv_date_fusion IS NULL
OR lv_rep IS NULL
THEN
RAISE err_non_parameter;
END IF;
SELECT NVL (organization_id, 'NULL')
INTO ln_org_id
FROM hr_all_organization_units haou
WHERE haou.NAME = lv_societe_absorbee;
----err_Soc_sr
IF ln_org_id = 'NULL'
THEN
RAISE err_soc_sr;
END IF;
BEGIN
----Création du fichier sorti
cgey_tools_pkg.put_log_message
('Création et Ouverture du fichier en lecture');
lv_name :=
'FUSION_fac_AP_EXTRAIRE'
|| TO_CHAR (SYSDATE, 'DDMMYYYY_HH24MISS')
|| '.txt';
cgey_tools_pkg.put_log_message ('Fichier sortie est ' || lv_name);
lt_id := UTL_FILE.fopen (lv_rep, lv_name, 'w');
IF UTL_FILE.is_open (lt_id)
THEN
cgey_tools_pkg.put_log_message (cv_line);
cgey_tools_pkg.put_log_message ( 'Creation OK du fichier: '
|| lv_name
ELSE
cgey_tools_pkg.put_log_message (cv_line);
cgey_tools_pkg.put_log_message
( 'Probleme ouverture du fichier '
|| lv_name
END IF;
----EXCEPTION UTL_FILE.WRITE_ERROR, UTL_FILE.INVALID_PATH
EXCEPTION
WHEN UTL_FILE.write_error
THEN
RAISE err_file_write;
WHEN UTL_FILE.invalid_path
THEN
RAISE err_file_invalid_path;
----Création du fichier sorti
END;
BEGIN
UTL_FILE.put_line (lt_id, vv_entete);
----CURSOR FACTURE A EXTRAIRE
OPEN cur_fusion_extract_ap_invoice (lv_societe_absorbee,
lv_societe_absorbante,
lv_date_fusion
LOOP
FETCH cur_fusion_extract_ap_invoice
INTO rec_fusion_extract_ap_invoice;
EXIT WHEN cur_fusion_extract_ap_invoice%NOTFOUND;
lv_invoice_id := rec_fusion_extract_ap_invoice.invoice_id;
ln_compteur_hold := 0;
lv_hode_reason := NULL;
lv_release_reason := NULL;
OPEN cur_ap_hold_invoices
(rec_fusion_extract_ap_invoice.invoice_id);
LOOP
FETCH cur_ap_hold_invoices
INTO rec_ap_hold_invoices;
EXIT WHEN cur_ap_hold_invoices%NOTFOUND;
----La première blocage à traiter
IF ln_compteur_hold = 0
THEN
lv_hode_reason :=
NVL (rec_ap_hold_invoices.hold_reason, ' ');
lv_release_reason :=
NVL (rec_ap_hold_invoices.release_reason, ' ');
----concatener des autres blocages suivants pour la même facture
ELSE
lv_hode_reason :=
lv_hode_reason
|| NVL (rec_ap_hold_invoices.hold_reason, ' ');
lv_release_reason :=
lv_release_reason
|| NVL (rec_ap_hold_invoices.release_reason, ' ');
END IF;
ln_compteur_hold := ln_compteur_hold + 1;
END LOOP;
CLOSE cur_ap_hold_invoices;
vv_buffer :=
NVL (lv_societe_absorbee, ' ')
|| vv_separator
|| NVL (lv_societe_absorbante, ' ')
|| vv_separator
|| NVL (TO_CHAR (lv_date_fusion, 'dd/mm/yyyy'), ' ')
|| vv_separator
|| NVL (TO_CHAR (rec_fusion_extract_ap_invoice.invoice_id),
|| vv_separator;
UTL_FILE.put_line (lt_id, vv_buffer);
ln_compteur_lignes := ln_compteur_lignes + 1;
END LOOP;
cgey_tools_pkg.put_log_message
( TO_CHAR (ln_compteur_lignes)
|| ' lignes inserees dans le fichier '
|| lv_rep
|| '/'
|| lv_name
CLOSE cur_fusion_extract_ap_invoice;
UTL_FILE.fclose (lt_id);
cgey_tools_pkg.put_log_message (' ');
cgey_tools_pkg.put_log_message (cv_line);
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
RAISE err_ecriture_file;
END;
EXCEPTION
WHEN err_non_parameter
THEN
pn_retcode := SQLCODE;
cgey_tools_pkg.put_log_message ('error' || SQLCODE);
cgey_tools_pkg.put_log_message
('error parameter : Veuillez vous verifier la configuration dans la table CGEY_PARAMETERS!'
WHEN err_soc_sr
THEN
pn_retcode := SQLCODE;
cgey_tools_pkg.put_log_message ('error' || SQLCODE);
cgey_tools_pkg.put_log_message
('error société_absorbée : Veuillez vous verifier le parameter de la société absorbée !'
WHEN err_file_write
THEN
UTL_FILE.fclose (lt_id);
pv_errbuff := SQLERRM;
pn_retcode := SQLCODE;
cgey_tools_pkg.put_log_message ('error' || SQLCODE);
cgey_tools_pkg.put_log_message ('erreur write_error:' || pv_errbuff);
WHEN err_file_invalid_path
THEN
UTL_FILE.fclose (lt_id);
pn_retcode := SQLCODE;
pv_errbuff := SQLERRM;
cgey_tools_pkg.put_log_message ('error' || SQLCODE);
cgey_tools_pkg.put_log_message ('erreur invalid_path:' || pv_errbuff);
WHEN err_ecriture_file
THEN
UTL_FILE.fclose (lt_id);
pn_retcode := SQLCODE;
pv_errbuff := SQLERRM;
cgey_tools_pkg.put_log_message ('error' || SQLCODE);
cgey_tools_pkg.put_log_message ('err_ecriture_file:' || pv_errbuff);
WHEN OTHERS
THEN
cgey_tools_pkg.put_log_message
('Une Erreur inconnue arrive lors que l''extraction du FUSION_fac_AP_EXTRAIRE!!'
END main_fusion_extract;
END spr_ap_fusion_extract_pkg;*009*
Edited by: 009 on Mar 11, 2010 3:31 AM -
Issue with UTL_FILE Utility
Hi
I have a program to create source codes based on the input parameters passed. I am able to successfully print it too. But when i try to directly write those lines into a file it writes only the last line. Please check the code written in CONCAT_STR_RND where i call the procedure L_WRITE_TRG_FILES to write to a file.
I knew i am missing some thing silly here in looping constructs or what ever but could not trace that out. Request the forum users to get that resolved and help.
Code used for creating the procedure is shown below.
--File Generating Procedure
-- This just creates a Sequence for the table passed in the Parameter
CREATE OR REPLACE PROCEDURE gen_seq(p_tab IN VARCHAR2, p_col IN VARCHAR2) IS
l_ltab VARCHAR2(100) := LOWER(p_tab);
l_lcol VARCHAR2(100) := LOWER(p_col);
BEGIN
*--Simple Creation of Sequence for Table. I would like to save this into a file*.
CONCAT_STR_RND('CREATE SEQUENCE ' || l_ltab);
CONCAT_STR_RND('/');
END;
--Procedure which concateneates String to form as a code.
CREATE OR REPLACE PROCEDURE CONCAT_STR_RND(STR IN VARCHAR2,
LEN IN INTEGER := 80,
EXPAND_IN IN BOOLEAN := TRUE) IS
V_LEN PLS_INTEGER := LEAST(LEN, 255);
V_STR VARCHAR2(2000);
I INTEGER;
BEGIN
IF LENGTH(STR) > V_LEN THEN
V_STR := SUBSTR(STR, 1, V_LEN);
DBMS_OUTPUT.PUT_LINE(V_STR);
CONCAT_STR_RND(SUBSTR(STR, LEN + 1), V_LEN, EXPAND_IN);
ELSE
I := I + 1;
V_STR := STR;
DBMS_OUTPUT.PUT_LINE((V_STR));
END IF;
L_WRITE_TRG_FILES(P_FILE_DIR => 'PUBLIC_ACCESS',
P_FILE_NAME => 'EMPLOYEES' --,
-- P_FILE_TXT => V_STR
END CONCAT_STR_RND;
-- Procedure to write text into File using UTL_FILE Utility.
CREATE OR REPLACE PROCEDURE L_WRITE_TRG_FILES(P_FILE_DIR IN VARCHAR2,
P_FILE_NAME IN VARCHAR2 --,
--P_FILE_TXT IN VARCHAR2
) IS
M_BUFFER_SIZE CONSTANT BINARY_INTEGER := 32767;
M_FILE_DIR VARCHAR2(80);
M_FILE_HANDLE UTL_FILE.FILE_TYPE;
M_FILE_NAME VARCHAR2(240);
M_BUFFER VARCHAR2(32766);
CURSOR C1 IS
SELECT V_TRG_SOURCE_TEXT
FROM MIG_TEMP_TABLE
WHERE V_TAB_NAME = P_FILE_NAME
ORDER BY V_LINENUM;
PROCEDURE WRITE_INIT(P_OPEN_MODE IN VARCHAR2 DEFAULT 'W') IS
BEGIN
UTL_FILE.FCLOSE_ALL;
M_FILE_HANDLE := UTL_FILE.FOPEN(LOCATION => M_FILE_DIR,
FILENAME => M_FILE_NAME,
OPEN_MODE => P_OPEN_MODE,
MAX_LINESIZE => M_BUFFER_SIZE);
END WRITE_INIT;
PROCEDURE WRITE_LINE(P_BUFFER VARCHAR2) IS
BEGIN
UTL_FILE.PUT_LINE(FILE => M_FILE_HANDLE,
BUFFER => P_BUFFER,
AUTOFLUSH => FALSE);
M_BUFFER := NULL;
END WRITE_LINE;
PROCEDURE CLOSE_FILE IS
BEGIN
IF UTL_FILE.IS_OPEN(FILE => M_FILE_HANDLE) THEN
UTL_FILE.FCLOSE(FILE => M_FILE_HANDLE);
END IF;
END CLOSE_FILE;
BEGIN
M_FILE_DIR := P_FILE_DIR;
M_FILE_NAME := P_FILE_NAME || '_REL.sql';
WRITE_INIT;
FOR I IN C1 LOOP
WRITE_LINE(I.V_TRG_SOURCE_TEXT);
END LOOP;
CLOSE_FILE;
END L_WRITE_TRG_FILES; Thanks in advance.This a one piece of grossly overcomplicated code that can be replaced with about 20 lines of normal code. Anyway, your code performs open file+write line+close file for each line (what a mess) and it always opens file for write (P_OPEN_MODE IN VARCHAR2 DEFAULT 'W') which means file is overwritten each time. You need to change your code to pass P_OPEN_MODE parameter to you file writing procedure. Then call it with P_OPEN_MODE 'W' (write) for the first line and 'A' (append) for next lines.
SY. -
Problem : Load PDF or similiar files( stored at operating system) into an oracle table using SQl*Loader .
and than Unload the files back from oracle tables to prevoius format.
I 've used SQL*LOADER .... " sqlldr " command as :
" sqlldr scott/[email protected] control=c:\sqlldr\control.ctl log=c:\any.txt "
Control file is written as :
LOAD DATA
INFILE 'c:\sqlldr\r_sqlldr.txt'
REPLACE
INTO table r_sqlldr
Fields terminated by ','
id sequence (max,1) ,
fname char(20),
data LOBFILE(fname) terminated by EOF )
It loads files ( Pdf, Image and more...) that are mentioned in file r_sqlldr.txt into oracle table r_sqlldr
Text file ( used as source ) is written as :
c:\kalam.pdf,
c:\CTSlogo1.bmp
c:\any1.txt
after this load ....i used UTL_FILE to unload data and write procedure like ...
CREATE OR REPLACE PROCEDURE R_UTL AS
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER ;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
SELECT data
INTO l_blob
FROM r_sqlldr
where id= 1;
l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
DBMS_OUTPUT.PUT_LINE('blob length : ' || l_blob_len);
IF (l_blob_len < 32767) THEN
l_amount :=l_blob_len;
ELSE
l_amount := 32767;
END IF;
DBMS_LOB.OPEN(l_blob, DBMS_LOB.LOB_READONLY);
l_file := UTL_FILE.FOPEN('DBDIR1','Kalam_out.pdf','w', 32767);
DBMS_OUTPUT.PUT_LINE('File opened');
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.READ (l_blob, l_amount, l_pos, l_buffer);
DBMS_OUTPUT.PUT_LINE('Blob read');
l_pos := l_pos + l_amount;
UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
DBMS_OUTPUT.PUT_LINE('writing to file');
UTL_FILE.FFLUSH(l_file);
UTL_FILE.NEW_LINE(l_file);
END LOOP;
UTL_FILE.FFLUSH(l_file);
UTL_FILE.FCLOSE(l_file);
DBMS_OUTPUT.PUT_LINE('File closed');
DBMS_LOB.CLOSE(l_blob);
EXCEPTION
WHEN OTHERS THEN
IF UTL_FILE.IS_OPEN(l_file) THEN
UTL_FILE.FCLOSE(l_file);
END IF;
DBMS_OUTPUT.PUT_LINE('Its working at last');
END R_UTL;
This loads data from r_sqlldr table (BOLBS) to files on operating system ,,,
-> Same procedure with minor changes is used to unload other similar files like Images and text files.
In above example : Loading : 3 files 1) Kalam.pdf 2) CTSlogo1.bmp 3) any1.txt are loaded into oracle table r_sqlldr 's 3 rows respectively.
file names into fname column and corresponding data into data ( BLOB) column.
Unload : And than these files are loaded back into their previous format to operating system using UTL_FILE feature of oracle.
so PROBLEM IS : Actual capacity (size ) of these files is getting unloaded back but with quality decreased. And PDF file doesnt even view its data. means size is almot equal to source file but data are lost when i open it.....
and for images .... imgaes are getting loaded an unloaded but with colors changed ....
Also features ( like FFLUSH ) of Oracle 've been used but it never worked
ANY SUGGESTIONS OR aLTERNATE SOLUTION TO LOAD AND UNLOAD PDFs through Oracle ARE REQUESTED.
------------------------------------------------------------------------------------------------------------------------Thanks Justin ...for a quick response ...
well ... i am loading data into BLOB only and using SQL*Loader ...
I've never used dbms_lob.loadFromFile to do the loads ...
i 've opend a file on network and than used dbms_lob.read and
UTL_FILE.PUT_RAW to read and write data into target file.
actually ...my process is working fine with text files but not with PDF and IMAGES ...
and your doubt of ..."Is the data the proper length after reading it in?" ..m not getting wat r you asking ...but ... i think regarding data length ..there is no problem... except ... source PDF length is 90.4 kb ..and Target is 90.8 kb..
thats it...
So Request u to add some more help ......or should i provide some more details ?? -
Utl_file truncates the line and fillowing records
Here is my code ,I am seeing an unusual problem It was all ok untill two weeks ago . AfterI made somechanges (added || Chr(13)|| Chr(10) to the ce_line at the end) , A csv file that should have more that 500 records is being truncated , after nearly 113 lines , i dont see any data . It looks some thing like Below. It terminates in between the line and no data after that .
I looked at the DBM_Output , Its shows me all 500+ records , Looks like the problem while writing to the file some things is going wrong.
Or is it because of some data issue that its does'nt consider.
"602992121 602992121 DATASCRUB 602992121 W 3/31/2011 6/1/2011 5/1/2031 4.875 400000
602992315 602992315 DATASCRUB 602992315 W DATASCRUB 602992315 K 3/14/2011 5/1/2011 4/1/2031 4.75 153000
602992336 602992336 DATASCRUB 602992336 DATASCRUB 602992336 3/28/2011 5/1/2011 4/1/2031 4.75 278400
602992717 602992717 DATASCRU
CE_LINE VARCHAR2 (500);
CE_FILE UTL_FILE.FILE_TYPE;
L_C1 to L_C55 are defined SYS.ODCIVARCHAR2LIST;
L_LIMIT NUMBER := 1000;
<<Code>>
OPEN CUSTODIAN_EXTRACT_DETAILS FOR V_CHR_SQL;
IF UTL_FILE.IS_OPEN (CE_FILE) THEN
LOOP
FETCH CUSTODIAN_EXTRACT_DETAILS
BULK COLLECT INTO L_C1,
L_C2,L_C3,L_C4,L_C5,L_C6,L_C7,L_C8,L_C9,L_C10,L_C11,L_C12,L_C13,L_C14,L_C15,L_C16,L_C17,L_C18,L_C19,L_C20,L_C21,L_C22,L_C23,L_C24,L_C25,L_C26,L_C27,L_C28,L_C29,L_C30,L_C31,L_C32,L_C33,L_C34,L_C35,L_C36,L_C37,L_C38,L_C39,L_C40,L_C41,L_C42,L_C43,L_C44,L_C45,L_C46,L_C47,L_C48,L_C49,L_C50,L_C51,L_C52,L_C53,L_C54,L_C55 LIMIT L_LIMIT;
FOR I IN 1 .. L_C1.COUNT LOOP
IF INSTR (L_C21 (I), ',') > 0 THEN
L_C21 (I) := '"' || L_C21 (I) || '"';
END IF;
CE_LINE :=L_C1 (I) || ',' || L_C2 (I) || ',' || L_C3 (I)|| ','|| L_C4 (I)|| ','|| L_C5 (I)|| ','|| L_C6 (I)|| ','|| L_C7 (I)|| ','|| L_C8 (I)|| ','|| L_C9 (I)|| ','|| L_C10 (I)|| ','|| L_C11 (I)|| ','|| L_C12 (I)|| ','|| L_C13 (I)|| ','|| L_C14 (I)|| ','|| L_C15 (I)|| ','|| L_C16 (I)|| ','|| L_C17 (I)|| ','|| L_C18 (I)|| ','|| L_C19 (I)|| ','|| L_C20 (I)|| ','|| L_C21 (I)|| ','|| L_C22 (I)|| ','|| L_C23 (I) || ','|| L_C24 (I)|| ','|| L_C25 (I)|| ','|| L_C26 (I)|| ','|| L_C27 (I)|| ','|| L_C28 (I)|| ','|| L_C29 (I)|| ','|| L_C30 (I)|| ','|| L_C31 (I)|| ','|| L_C32 (I)|| ','|| L_C33 (I)|| ','|| L_C34 (I)|| ','|| L_C35 (I)|| ','|| L_C36 (I)|| ','|| L_C37 (I)|| ','|| L_C38 (I)|| ','|| L_C39 (I)|| ','|| L_C40 (I)|| ','|| L_C41 (I)|| ','|| L_C42 (I)|| ','|| L_C43 (I)|| ','|| L_C44 (I)|| ','|| L_C45 (I)|| ','|| L_C46 (I)|| ','|| L_C47 (I)|| ','|| L_C48 (I)|| ','|| L_C49 (I)|| ','|| L_C50 (I)|| ','|| L_C51 (I)|| ','|| L_C52 (I)|| ','|| L_C53 (I)|| ','|| L_C54 (I)|| ','|| L_C55 (I) || Chr(13)|| Chr(10);
UTL_FILE.PUT (CE_FILE, CE_LINE);
dbms_output.put_line (CE_LINE);
DBMS_OUTPUT.NEW_LINE;
END LOOP;
EXIT WHEN CUSTODIAN_EXTRACT_DETAILS%NOTFOUND;
end loop;
END IF;
CLOSE CUSTODIAN_EXTRACT_DETAILS;
END IF;
UTL_FILE.FCLOSE (CE_FILE);
<<Code>>This appears to be a duplicate of UTL_FILE create a csv with 1002, 2003 and 3004 rows empty. Having two threads open simultaneously in the same forum for the same issue is counterproductive. In which thread would you like us to answer? Please close whichever thread you don't want us to answer in.
It would be helpful if you used the \ tag (6 characters, all lower case) before and after your code to preserve formatting. That makes it much easier to read.
Exactly what changes did you make? Why did you add the CHR(13) || CHR(10)? Did you, at the same time, change utl_file.put_line to utl_file.put?
Justin -
Read option in UTL_FILE
I am using the utl_file package to read text file.As required i
have set the utl_file_dir parameter in init.ora and restarted
the database.I am having no problem when i am using
utl_file.fopen procedure with 'w' or 'a' mode it is working
fine but when i am try to oopen file with 'r' option it is
raising " invalid operation " exception.
Can any one Help me out ?
Thanking all in advanceWell, I don4t know how is your code, but I can give you the one
that I use and it4s goes fine:
in_file UTL_FILE.FILE_TYPE;
/* To open the file */
IF not UTL_FILE.IS_OPEN(in_file) THEN
in_file:=UTL_FILE.FOPEN(path,filename_in,'r');
END IF;
/* To read */
LOOP
UTL_FILE.GET_LINE(in_file,buffer);
END LOOP;
/* To finish */
EXCEPTION
WHEN NO_DATA_FOUND THEN
UTL_FILE.FCLOSE(in_file);
And, of course, the database user must have read access to the
file directory.
Hope this help you,
Ana -
Help in user defined exception handler
Hi
Can some one help in solving this error .
when i run my procedure i get this error which is given below .
ORA-06510 PL/SQL unhandeled user defined exception at line 7
Procedure FMG_EXTRACT_MOTORBIKE_NEWBUS (P_NSSC_YN VARCHAR2) IS
l_start date;
l_end date;
cursor motorbike_rec is
select
c.id,
k.id pak_id,
p.ref,
i.description,
i.current_status,
i.premium,
i.sum_insured,
mv.registration_no,
mv.cc_rating,
nl.ncl_level,
nl.percentage_discount,
dp.full_name main_driver,
dpd.birth_date,
e.user_name entered_by,
ep.full_name emp_name,
fmg_get_imposed_terms(i.id,'. ',';') imposed_terms
from
fmg_clients c,
fmg_client_paks k,
fmg_policies p,
fmg_Policy_items i,
fmg_mv_usages u,
fmg_people dp,
fmg_people_details dpd,
fmg_employees e,
fmg_people ep,
fmg_motor_vehicles mv,
fmg_ncb_levels nl
where i.date_created>=l_start
and i.date_created<l_end
and i.pol_id=p.id
and p.ctp_id=k.id
and k.cli_id=c.id
and i.id=u.poi_id(+)
and u.per_id=dp.id(+)
and dp.id=dpd.per_id(+)
and i.id=mv.poi_id(+)
and i.ncl_id=nl.id(+)
and ( (i.pit_pro_code in ('TFF','FMC','FMT','FMF','FBK','PMC','TPO','MCL'))
or (i.pit_pro_code = 'CMV' and i.pit_code = 'MCL')
or (i.pit_pro_code = 'PMS' and i.pit_code = 'MCL')
or (i.pit_pro_code = 'PMT' and i.pit_code in ('MCT','MCF'))
and i.user_created=e.user_name
and ( (e.business_unit='BCC' and P_NSSC_YN='Y') OR (nvl(e.business_unit,'X')<>'BCC' and P_NSSC_YN='N') )
and e.per_id=ep.id;
l_file UTL_FILE.FILE_TYPE;
l_file_name varchar2(100);
l_data VARCHAR2(4000);
BEGIN
if P_NSSC_YN='Y' then
l_start := trunc(sysdate)-1;
l_end := trunc(sysdate);
l_file_name := 'MotorCycle_Daily_'||to_char(l_start)||'.csv';
l_file := utl_file.fopen( fmg_re_filepath('SSC'), l_file_name, 'W' );
else
l_start := to_date('01-' || to_char(sysdate-28,'MM-YYYY'));
l_end := last_day(to_date('01-' || to_char(sysdate-28,'MM-YYYY')));
l_file_name := 'MotorCycle_Monthly_'||to_char(l_start)||'_'||to_char(l_end)||'.csv';
l_file := utl_file.fopen( fmg_re_filepath('GAU'), l_file_name, 'W' );
end if;
l_data := '"Client ID","Pak ID","Policy Ref","Item Desc","RegoNo","CC","Item Status","Premium","Sum Insured",' ||
'"NCB Level","NCB%","Main Driver","Birth Date","Imposed terms","EnteredBy","Employee Name"';
utl_file.put_line(l_file, l_data );
for i in motorbike_rec loop
l_data :=
to_char(i.id) || ',' ||
to_char(i.pak_id) || ',' ||
i.ref || ',' ||
'"' || i.description || '",' ||
'"' || i.registration_no || '",' ||
to_char(i.cc_Rating) || ',' ||
i.current_status || ',' ||
to_char(i.premium) || ',' ||
to_char(i.sum_insured) || ',' ||
to_char(i.ncl_level) || ',' ||
to_char(i.percentage_discount) || ',' ||
'"' || i.main_driver || '",' ||
to_char(i.birth_date) || ',' ||
'"' || i.imposed_terms || '",' ||
i.entered_by || ',' ||
'"' || i.emp_name || '"' ;
utl_file.put_line(l_file,l_data);
end loop;
utl_file.fclose( l_file );
exception
when others then
if utl_file.is_open(l_file) then
utl_file.fclose( l_file );
end if;
raise;
END;What does fmg_re_filepath('SSC') return? Are their sufficient rights with Oracle user on the location that is returned by this function?
Which OS are you using? -
Problem while reading file using UTL_FILE.get_line
Hi All,
I am having the following txt file with the following data.
1|2010-09-25T02:00:24+09:00
2|ProductCode|SerialNumber|OpcoID|IssueDate|AcceptDate|FinishingUsageCounter.FoldZ|FinishingUsageCounter.FoldLetterZ|FinishingUsageCounter.FoldLetterC|FinishingUsageCounter.FoldCenter|FinishingUsageCounter.Punch2|FinishingUsageCounter.Punch3|FinishingUsageCounter.Punch4|FinishingUsageCounter.StapleSingle|FinishingUsageCounter.StapleDual|FinishingUsageCounter.StapleQuad|FinishingUsageCounter.BindBook|FinishingUsageCounter.CoilPunch|FinishingUsageCounter.Trimming|FinishingUsageCounter.SquareFold|FAXUsageCounter.SendCount|FAXUsageCounter.SendImpressions|FAXUsageCounter.ReceivedCount0|FAXUsageCounter.ReceivedCount1|FAXUsageCounter.ReceivedCount2|FAXUsageCounter.ReceivedCount3|FAXUsageCounter.ReceivedCount4|FAXUsageCounter.ReceivedCount5|FAXUsageCounter.ReceivedImpressions0|FAXUsageCounter.ReceivedImpressions1|FAXUsageCounter.ReceivedImpressions2|FAXUsageCounter.ReceivedImpressions3|FAXUsageCounter.ReceivedImpressions4|FAXUsageCounter.ReceivedImpressions5|FAXUsageCounter.PrintImpressions0|FAXUsageCounter.PrintImpressions1|FAXUsageCounter.PrintImpressions2|FAXUsageCounter.PrintImpressions3|FAXUsageCounter.PrintImpressions4|FAXUsageCounter.PrintImpressions5|FAXUsageCounter.StoreForPollingPrintImpressions|FAXUsageCounter.PrintSheets0|FAXUsageCounter.PrintSheets1|FAXUsageCounter.PrintSheets2|FAXUsageCounter.PrintSheets3|FAXUsageCounter.PrintSheets4|FAXUsageCounter.PrintSheets5|FAXUsageCounter.StoreForPollingPrintSheets|FAXUsageCounter.PrintDuplexSheets0|FAXUsageCounter.PrintDuplexSheets1|FAXUsageCounter.PrintDuplexSheets2|FAXUsageCounter.PrintDuplexSheets3|FAXUsageCounter.PrintDuplexSheets4|FAXUsageCounter.PrintDuplexSheets5|FAXUsageCounter.StoreForPollingPrintDuplexSheets|FAXUsageCounter.PrintReverseSheets0|FAXUsageCounter.PrintReverseSheets1|FAXUsageCounter.PrintReverseSheets2|FAXUsageCounter.PrintReverseSheets3|FAXUsageCounter.PrintReverseSheets4|FAXUsageCounter.PrintReverseSheets5|FAXUsageCounter.StoreForPollingPrintReverseSheets|FAXUsageCounter.PrintLargeSheets0|FAXUsageCounter.PrintLargeSheets1|FAXUsageCounter.PrintLargeSheets2|FAXUsageCounter.PrintLargeSheets3|FAXUsageCounter.PrintLargeSheets4|FAXUsageCounter.PrintLargeSheets5|IFAXUsageCounter.SendCount|IFAXUsageCounter.SendImpressions|IFAXUsageCounter.ReceivedCount|IFAXUsageCounter.ReceivedImpressions|IFAXUsageCounter.PrintImpressions|IFAXUsageCounter.PrintSheets|IFAXUsageCounter.PrintDuplexSheets|IFAXUsageCounter.PrintReverseSheets|IFAXUsageCounter.PrintLargeSheets|DirectFAXUsageCounter.SendCount|DirectFAXUsageCounter.SendImpressions|ServerFAXUsageCounter.SendCount|ServerFAXUsageCounter.SendImpressions|ScanUsageCounter.BWImpressions|ScanUsageCounter.ColorImpressions|ScanUsageCounter.MailboxBWImpressions|ScanUsageCounter.MailboxColorImpressions|ScanUsageCounter.FileBWImpressions|ScanUsageCounter.FileColorImpressions|ScanUsageCounter.EMailBWImpressions|ScanUsageCounter.EMailColorImpressions|ScanUsageCounter.MediaBWImpressions|ScanUsageCounter.MediaColorImpressions|PrintUsageCounter.BWImpressions|PrintUsageCounter.ColorImpressions|PrintUsageCounter.BW2upImpressions|PrintUsageCounter.Color2upImpressions|PrintUsageCounter.BWNupImpressions|PrintUsageCounter.ColorNupImpressions|PrintUsageCounter.BWSheets|PrintUsageCounter.ColorSheets|PrintUsageCounter.BWDuplexSheets|PrintUsageCounter.ColorDuplexSheets|PrintUsageCounter.BWReverseSheets|PrintUsageCounter.ColorReverseSheets|PrintUsageCounter.BWLargeSheets|PrintUsageCounter.ColorLargeSheets|DiagPrintUsageCounter.BWImpressions|DiagPrintUsageCounter.ColorImpressions|DiagPrintUsageCounter.BWSheets|DiagPrintUsageCounter.ColorSheets|DiagPrintUsageCounter.BWLargeSheets|DiagPrintUsageCounter.ColorLargeSheets|CopyUsageCounter.BWImpressions|CopyUsageCounter.ColorImpressions|CopyUsageCounter.BW2upImpressions|CopyUsageCounter.Color2upImpressions|CopyUsageCounter.BWNupImpressions|CopyUsageCounter.ColorNupImpressions|CopyUsageCounter.BWSheets|CopyUsageCounter.ColorSheets|CopyUsageCounter.BWDuplexSheets|CopyUsageCounter.ColorDuplexSheets|CopyUsageCounter.BWReverseSheets|CopyUsageCounter.ColorReverseSheets|CopyUsageCounter.BWLargeSheets|CopyUsageCounter.ColorLargeSheets|ReportUsageCounter.BWImpressions|ReportUsageCounter.ColorImpressions|ReportUsageCounter.BWSheets|ReportUsageCounter.ColorSheets|ReportUsageCounter.BWDuplexSheets|ReportUsageCounter.ColorDuplexSheets|ReportUsageCounter.BWReverseSheets|ReportUsageCounter.ColorReverseSheets|ReportUsageCounter.BWLargeSheets|ReportUsageCounter.ColorLargeSheets|LargeSizeUsageCounter.BWImpressions|LargeSizeUsageCounter.ColorImpressions|PaperSizeUsageCounter.A4|PaperSizeUsageCounter.UNSPECIFIED|FAXUsageCounter.SendCount0|FAXUsageCounter.SendCount1|FAXUsageCounter.SendCount2|FAXUsageCounter.SendCount3|FAXUsageCounter.SendCount4|FAXUsageCounter.SendCount5|FAXUsageCounter.SendImpressions0|FAXUsageCounter.SendImpressions1|FAXUsageCounter.SendImpressions2|FAXUsageCounter.SendImpressions3|FAXUsageCounter.SendImpressions4|FAXUsageCounter.SendImpressions5|FAXUsageCounter.PrintBW2upImpressions|FAXUsageCounter.BW1ImpressionJob|FAXUsageCounter.BW2ImpressionsJob|FAXUsageCounter.BW3ImpressionsJob|FAXUsageCounter.BW4ImpressionsJob|FAXUsageCounter.BW5ImpressionsJob|FAXUsageCounter.BW6ImpressionsJob|FAXUsageCounter.BW7ImpressionsJob|FAXUsageCounter.BW8ImpressionsJob|FAXUsageCounter.BW9ImpressionsJob|FAXUsageCounter.BW10To19ImpressionsJob|FAXUsageCounter.BW20To29ImpressionsJob|FAXUsageCounter.BW30To49ImpressionsJob|FAXUsageCounter.BW50To74ImpressionsJob|FAXUsageCounter.BW75To99ImpressionsJob|FAXUsageCounter.BW100To249ImpressionsJob|FAXUsageCounter.BWOver250ImpressionsJob|FAXUsageCounter.TotalTimeSent0|FAXUsageCounter.TotalTimeSent1|FAXUsageCounter.TotalTimeSent2|FAXUsageCounter.TotalTimeSent3|FAXUsageCounter.TotalTimeSent4|FAXUsageCounter.TotalTimeSent5|FAXUsageCounter.TotalTimeReceived0|FAXUsageCounter.TotalTimeReceived1|FAXUsageCounter.TotalTimeReceived2|FAXUsageCounter.TotalTimeReceived3|FAXUsageCounter.TotalTimeReceived4|FAXUsageCounter.TotalTimeReceived5|IFAXUsageCounter.Print2upImpressions|IFAXUsageCounter.BW1ImpressionJob|IFAXUsageCounter.BW2ImpressionsJob|IFAXUsageCounter.BW3ImpressionsJob|IFAXUsageCounter.BW4ImpressionsJob|IFAXUsageCounter.BW5ImpressionsJob|IFAXUsageCounter.BW6ImpressionsJob|IFAXUsageCounter.BW7ImpressionsJob|IFAXUsageCounter.BW8ImpressionsJob|IFAXUsageCounter.BW9ImpressionsJob|IFAXUsageCounter.BW10To19ImpressionsJob|IFAXUsageCounter.BW20To29ImpressionsJob|IFAXUsageCounter.BW30To49ImpressionsJob|IFAXUsageCounter.BW50To74ImpressionsJob|IFAXUsageCounter.BW75To99ImpressionsJob|IFAXUsageCounter.BW100To249ImpressionsJob|IFAXUsageCounter.BWOver250ImpressionsJob|DirectFAXUsageCounter.SendCount0|DirectFAXUsageCounter.SendCount1|DirectFAXUsageCounter.SendCount2|DirectFAXUsageCounter.SendCount3|DirectFAXUsageCounter.SendCount4|DirectFAXUsageCounter.SendCount5|DirectFAXUsageCounter.SendImpressions0|DirectFAXUsageCounter.SendImpressions1|DirectFAXUsageCounter.SendImpressions2|DirectFAXUsageCounter.SendImpressions3|DirectFAXUsageCounter.SendImpressions4|DirectFAXUsageCounter.SendImpressions5|PrintUsageCounter.BW2upSimplexImpressions|PrintUsageCounter.Color2upSimplexImpressions|PrintUsageCounter.BW2upDuplexImpressions|PrintUsageCounter.Color2upDuplexImpressions|PrintUsageCounter.BW4upSimplexImpressions|PrintUsageCounter.Color4upSimplexImpressions|PrintUsageCounter.BW4upDuplexImpressions|PrintUsageCounter.Color4upDuplexImpressions|PrintUsageCounter.BWNupSimplexImpressions|PrintUsageCounter.ColorNupSimplexImpressions|PrintUsageCounter.BWNupDuplexImpressions|PrintUsageCounter.ColorNupDuplexImpressions|PrintUsageCounter.BW1ImpressionJob|PrintUsageCounter.BW2ImpressionsJob|PrintUsageCounter.BW3ImpressionsJob|PrintUsageCounter.BW4ImpressionsJob|PrintUsageCounter.BW5ImpressionsJob|PrintUsageCounter.BW6ImpressionsJob|PrintUsageCounter.BW7ImpressionsJob|PrintUsageCounter.BW8ImpressionsJob|PrintUsageCounter.BW9ImpressionsJob|PrintUsageCounter.BW10To19ImpressionsJob|PrintUsageCounter.BW20To29ImpressionsJob|PrintUsageCounter.BW30To49ImpressionsJob|PrintUsageCounter.BW50To74ImpressionsJob|PrintUsageCounter.BW75To99ImpressionsJob|PrintUsageCounter.BW100To249ImpressionsJob|PrintUsageCounter.BWOver250ImpressionsJob|PrintUsageCounter.Color1ImpressionJob|PrintUsageCounter.Color2ImpressionsJob|PrintUsageCounter.Color3ImpressionsJob|PrintUsageCounter.Color4ImpressionsJob|PrintUsageCounter.Color5ImpressionsJob|PrintUsageCounter.Color6ImpressionsJob|PrintUsageCounter.Color7ImpressionsJob|PrintUsageCounter.Color8ImpressionsJob|PrintUsageCounter.Color9ImpressionsJob|PrintUsageCounter.Color10To19ImpressionsJob|PrintUsageCounter.Color20To29ImpressionsJob|PrintUsageCounter.Color30To49ImpressionsJob|PrintUsageCounter.Color50To74ImpressionsJob|PrintUsageCounter.Color75To99ImpressionsJob|PrintUsageCounter.Color100To249ImpressionsJob|PrintUsageCounter.ColorOver250ImpressionsJob|CopyUsageCounter.BW2upSimplexImpressions|CopyUsageCounter.Color2upSimplexImpressions|CopyUsageCounter.BW2upDuplexImpressions|CopyUsageCounter.Color2upDuplexImpressions|CopyUsageCounter.BW4upSimplexImpressions|CopyUsageCounter.Color4upSimplexImpressions|CopyUsageCounter.BW4upDuplexImpressions|CopyUsageCounter.Color4upDuplexImpressions|CopyUsageCounter.BWNupSimplexImpressions|CopyUsageCounter.ColorNupSimplexImpressions|CopyUsageCounter.BWNupDuplexImpressions|CopyUsageCounter.ColorNupDuplexImpressions|CopyUsageCounter.BWSimplexToDuplexSheets|CopyUsageCounter.ColorSimplexToDuplexSheets|CopyUsageCounter.BWDuplexToDuplexSheets|CopyUsageCounter.ColorDuplexToDuplexSheets|CopyUsageCounter.BWSimplexToSimplexSheets|CopyUsageCounter.ColorSimplexToSimplexSheets|CopyUsageCounter.BWDuplexToSimplexSheets|CopyUsageCounter.ColorDuplexToSimplexSheets|CopyUsageCounter.BW1ImpressionJob|CopyUsageCounter.BW2ImpressionsJob|CopyUsageCounter.BW3ImpressionsJob|CopyUsageCounter.BW4ImpressionsJob|CopyUsageCounter.BW5ImpressionsJob|CopyUsageCounter.BW6ImpressionsJob|CopyUsageCounter.BW7ImpressionsJob|CopyUsageCounter.BW8ImpressionsJob|CopyUsageCounter.BW9ImpressionsJob|CopyUsageCounter.BW10To19ImpressionsJob|CopyUsageCounter.BW20To29ImpressionsJob|CopyUsageCounter.BW30To49ImpressionsJob|CopyUsageCounter.BW50To74ImpressionsJob|CopyUsageCounter.BW75To99ImpressionsJob|CopyUsageCounter.BW100To249ImpressionsJob|CopyUsageCounter.BWOver250ImpressionsJob|CopyUsageCounter.Color1ImpressionJob|CopyUsageCounter.Color2ImpressionsJob|CopyUsageCounter.Color3ImpressionsJob|CopyUsageCounter.Color4ImpressionsJob|CopyUsageCounter.Color5ImpressionsJob|CopyUsageCounter.Color6ImpressionsJob|CopyUsageCounter.Color7ImpressionsJob|CopyUsageCounter.Color8ImpressionsJob|CopyUsageCounter.Color9ImpressionsJob|CopyUsageCounter.Color10To19ImpressionsJob|CopyUsageCounter.Color20To29ImpressionsJob|CopyUsageCounter.Color30To49ImpressionsJob|CopyUsageCounter.Color50To74ImpressionsJob|CopyUsageCounter.Color75To99ImpressionsJob|CopyUsageCounter.Color100To249ImpressionsJob|CopyUsageCounter.ColorOver250ImpressionsJob|CopyUsageCounter.BW1OriginalJob|CopyUsageCounter.BW2OriginalsJob|CopyUsageCounter.BW3OriginalsJob|CopyUsageCounter.BW4OriginalsJob|CopyUsageCounter.BW5OriginalsJob|CopyUsageCounter.BW6OriginalsJob|CopyUsageCounter.BW7OriginalsJob|CopyUsageCounter.BW8OriginalsJob|CopyUsageCounter.BW9OriginalsJob|CopyUsageCounter.BW10To19OriginalsJob|CopyUsageCounter.BW20To29OriginalsJob|CopyUsageCounter.BW30To49OriginalsJob|CopyUsageCounter.BW50To74OriginalsJob|CopyUsageCounter.BW75To99OriginalsJob|CopyUsageCounter.BW100To249OriginalsJob|CopyUsageCounter.BWOver250OriginalsJob|CopyUsageCounter.Color1OriginalJob|CopyUsageCounter.Color2OriginalsJob|CopyUsageCounter.Color3OriginalsJob|CopyUsageCounter.Color4OriginalsJob|CopyUsageCounter.Color5OriginalsJob|CopyUsageCounter.Color6OriginalsJob|CopyUsageCounter.Color7OriginalsJob|CopyUsageCounter.Color8OriginalsJob|CopyUsageCounter.Color9OriginalsJob|CopyUsageCounter.Color10To19OriginalsJob|CopyUsageCounter.Color20To29OriginalsJob|CopyUsageCounter.Color30To49OriginalsJob|CopyUsageCounter.Color50To74OriginalsJob|CopyUsageCounter.Color75To99OriginalsJob|CopyUsageCounter.Color100To249OriginalsJob|CopyUsageCounter.ColorOver250OriginalsJob|PaperSizeUsageCounter.A3|PaperTrayUsageCounter.Tray1PrintedSheets|PaperTrayUsageCounter.Tray2PrintedSheets|PaperTrayUsageCounter.Tray3PrintedSheets|PaperTrayUsageCounter.Tray4PrintedSheets|PaperTrayUsageCounter.Tray5PrintedSheets|PaperTrayUsageCounter.Tray6PrintedSheets|PaperTrayUsageCounter.Tray7PrintedSheets|PaperTrayUsageCounter.Tray8PrintedSheets|PaperTrayUsageCounter.Tray1PrintedImpressions|PaperTrayUsageCounter.Tray2PrintedImpressions|PaperTrayUsageCounter.Tray3PrintedImpressions|PaperTrayUsageCounter.Tray4PrintedImpressions|PaperTrayUsageCounter.Tray5PrintedImpressions|PaperTrayUsageCounter.Tray6PrintedImpressions|PaperTrayUsageCounter.Tray7PrintedImpressions|PaperTrayUsageCounter.Tray8PrintedImpressions|StoredDocumentUsageCounter.UnprintedDeletedImpressions|UptimeUsageCounter.WarmUpTime|UptimeUsageCounter.IOTRunTime|UptimeUsageCounter.IITRunTime|UptimeUsageCounter.LowPowerTime|UptimeUsageCounter.SleepTime|UptimeUsageCounter.StandbyTime|UptimeUsageCounter.PowerOffTime
3|ABCDEF|110139|ABC|2010-09-24T12:32:00+09:00|2010-09-24T12:32:28+09:00|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||0|0|0|0|0|0|0|0|0|0|0|0|0|309|159|158|16|0|0|151|129|0|0|4709|2105|1971|704|2|0|2760|1407|1877|769|0|0|47|86|0|0|0|0|0|0|305|21|1|0|0|0|204|18|101|3|0|0|1|1|60|0|51|0|9|0|0|0|0|0|77|92|4309|0|0|5|0|0|0|0|0|19|0|0|0|0|0|1|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|355|0|0|0|0|0|319|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|21|10|1950|694|0|0|2|0|0|0|2|0|422|292|60|38|24|18|18|26|8|60|34|20|3|0|0|0|233|138|36|30|10|20|9|11|7|27|17|6|2|1|0|0|1|0|0|0|0|0|0|0|0|0|0|0|5|1|96|2|103|15|0|0|84|7|0|4|1|0|0|0|0|0|1|0|0|0|1|0|13|4|0|0|0|0|0|0|0|0|0|0|0|0|0|0|80|12|0|3|1|0|0|0|0|1|0|0|1|0|0|0|14|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|135|3631|658|11|135|9|0|0|0|5901|1114|11|169|9|0|0|0|0|66|513|29|5715|102714|11941|28
3|ABCDEF|110139|ABC|2010-09-24T13:34:00+09:00|2010-09-24T13:34:16+09:00|0|0|0|0|0|0|0|0|0|0|0|0|0|0|5|19|0|6|0|0|0|0|0|4|0|0|0|0|0|4|0|0|0|0|0|0|4|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|309|159|158|16|0|0|151|129|0|0|4709|2105|1971|704|2|0|2760|1407|1877|769|0|0|47|86|0|0|0|0|0|0|305|21|1|0|0|0|204|18|101|3|0|0|1|1|60|0|51|0|9|0|0|0|0|0|77|92|4309|0|0|5|0|0|0|0|0|19|0|0|0|0|0|1|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|355|0|0|0|0|0|319|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|21|10|1950|694|0|0|2|0|0|0|2|0|422|292|60|38|24|18|18|26|8|60|34|20|3|0|0|0|233|138|36|30|10|20|9|11|7|27|17|6|2|1|0|0|1|0|0|0|0|0|0|0|0|0|0|0|5|1|96|2|103|15|0|0|84|7|0|4|1|0|0|0|0|0|1|0|0|0|1|0|13|4|0|0|0|0|0|0|0|0|0|0|0|0|0|0|80|12|0|3|1|0|0|0|0|1|0|0|1|0|0|0|14|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|135|3631|658|11|135|9|0|0|0|5901|1114|11|169|9|0|0|0|0|66|513|29|5730|102741|11960|28
4|2010-09-25T02:00:24+09:00|2
Following is the code i am using to read the file contents.
DECLARE
v_file_in UTL_FILE.file_type;
v_str VARCHAR2 (32767);
po_error_txt VARCHAR2 (2000) := 0;
po_success boolean;
BEGIN
v_file_in := UTL_FILE.fopen ('GB_EPINDIR', 'USAGECOUNTER20100925020020.txt', 'R');
LOOP
BEGIN
UTL_FILE.get_line (v_file_in, v_str,32767);
dbms_output.put_line(v_str);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
WHEN OTHERS THEN
po_error_txt := SUBSTR (SQLERRM, 1, 500);
po_success := FALSE;
EXIT;
END;
END LOOP;
END;
When loop comes on 2|ProductCode|Serial................... its through the error.
Please help me to resolve this problem.
Thanks & Regards
Uzair Hasan Nizami
Edited by: Uzair Hasan Nizami on Oct 5, 2010 1:44 PMUzair Hasan Nizami wrote:
See You have changed the second line. I mean you have split the line in two parts.No, I did not. Used exactly as you posted. To prove I added line number display:
SQL> DECLARE
2 v_file_in UTL_FILE.file_type;
3 v_str VARCHAR2 (32767);
4 po_error_txt VARCHAR2 (2000) := 0;
5 po_success boolean;
6 v_line_num number := 0;
7 BEGIN
8 v_file_in := UTL_FILE.fopen ('GB_EPINDIR', 'USAGECOUNTER20100925020020.txt', 'R',32767);
9 LOOP
10 BEGIN
11 v_line_num := v_line_num + 1;
12 UTL_FILE.get_line (v_file_in, v_str,32767);
13 dbms_output.put_line('============= Line ' || v_line_num || ' =================');
14 dbms_output.put_line(v_str);
15 EXCEPTION
16 WHEN NO_DATA_FOUND THEN
17 EXIT;
18 WHEN OTHERS THEN
19 po_error_txt := SUBSTR (SQLERRM, 1, 500);
20 po_success := FALSE;
21 dbms_output.put_line(po_error_txt);
22 EXIT;
23 END;
24 END LOOP;
25 IF UTL_FILE.IS_OPEN(v_file_in) THEN UTL_FILE.FCLOSE(v_file_in); END IF;
26 END;
27 /
============= Line 1 =================
1|2010-09-25T02:00:24+09:00
============= Line 2 =================
2|ProductCode|SerialNumber|OpcoID|IssueDate|AcceptDate|FinishingUsageCounter.Fol
dZ|FinishingUsageCounter.FoldLetterZ|FinishingUsageCounter.FoldLetterC|Finishing
UsageCounter.FoldCenter|FinishingUsageCounter.Punch2|FinishingUsageCounter.Punch
3|FinishingUsageCounter.Punch4|FinishingUsageCounter.StapleSingle|FinishingUsage
Counter.StapleDual|FinishingUsageCounter.StapleQuad|FinishingUsageCounter.BindBo
ok|FinishingUsageCounter.CoilPunch|FinishingUsageCounter.Trimming|FinishingUsage
Counter.SquareFold|FAXUsageCounter.SendCount|FAXUsageCounter.SendImpressions|FAX
UsageCounter.ReceivedCount0|FAXUsageCounter.ReceivedCount1|FAXUsageCounter.Recei
vedCount2|FAXUsageCounter.ReceivedCount3|FAXUsageCounter.ReceivedCount4|FAXUsage
Counter.ReceivedCount5|FAXUsageCounter.ReceivedImpressions0|FAXUsageCounter.Rece
ivedImpressions1|FAXUsageCounter.ReceivedImpressions2|FAXUsageCounter.ReceivedIm
pressions3|FAXUsageCounter.ReceivedImpressions4|FAXUsageCounter.ReceivedImpressi
ons5|FAXUsageCounter.PrintImpressions0|FAXUsageCounter.PrintImpressions1|FAXUsag
eCounter.PrintImpressions2|FAXUsageCounter.PrintImpressions3|FAXUsageCounter.Pri
ntImpressions4|FAXUsageCounter.PrintImpressions5|FAXUsageCounter.StoreForPolling
PrintImpressions|FAXUsageCounter.PrintSheets0|FAXUsageCounter.PrintSheets1|FAXUs
ageCounter.PrintSheets2|FAXUsageCounter.PrintSheets3|FAXUsageCounter.PrintSheets
4|FAXUsageCounter.PrintSheets5|FAXUsageCounter.StoreForPollingPrintSheets|FAXUsa
geCounter.PrintDuplexSheets0|FAXUsageCounter.PrintDuplexSheets1|FAXUsageCounter.
PrintDuplexSheets2|FAXUsageCounter.PrintDuplexSheets3|FAXUsageCounter.PrintDuple
xSheets4|FAXUsageCounter.PrintDuplexSheets5|FAXUsageCounter.StoreForPollingPrint
DuplexSheets|FAXUsageCounter.PrintReverseSheets0|FAXUsageCounter.PrintReverseShe
ets1|FAXUsageCounter.PrintReverseSheets2|FAXUsageCounter.PrintReverseSheets3|FAX
UsageCounter.PrintReverseSheets4|FAXUsageCounter.PrintReverseSheets5|FAXUsageCou
nter.StoreForPollingPrintReverseSheets|FAXUsageCounter.PrintLargeSheets0|FAXUsag
eCounter.PrintLargeSheets1|FAXUsageCounter.PrintLargeSheets2|FAXUsageCounter.Pri
ntLargeSheets3|FAXUsageCounter.PrintLargeSheets4|FAXUsageCounter.PrintLargeSheet
s5|IFAXUsageCounter.SendCount|IFAXUsageCounter.SendImpressions|IFAXUsageCounter.
ReceivedCount|IFAXUsageCounter.ReceivedImpressions|IFAXUsageCounter.PrintImpress
ions|IFAXUsageCounter.PrintSheets|IFAXUsageCounter.PrintDuplexSheets|IFAXUsageCo
unter.PrintReverseSheets|IFAXUsageCounter.PrintLargeSheets|DirectFAXUsageCounter
.SendCount|DirectFAXUsageCounter.SendImpressions|ServerFAXUsageCounter.SendCount
|ServerFAXUsageCounter.SendImpressions|ScanUsageCounter.BWImpressions|ScanUsageC
ounter.ColorImpressions|ScanUsageCounter.MailboxBWImpressions|ScanUsageCounter.M
ailboxColorImpressions|ScanUsageCounter.FileBWImpressions|ScanUsageCounter.FileC
olorImpressions|ScanUsageCounter.EMailBWImpressions|ScanUsageCounter.EMailColorI
mpressions|ScanUsageCounter.MediaBWImpressions|ScanUsageCounter.MediaColorImpres
sions|PrintUsageCounter.BWImpressions|PrintUsageCounter.ColorImpressions|PrintUs
ageCounter.BW2upImpressions|PrintUsageCounter.Color2upImpressions|PrintUsageCoun
ter.BWNupImpressions|PrintUsageCounter.ColorNupImpressions|PrintUsageCounter.BWS
heets|PrintUsageCounter.ColorSheets|PrintUsageCounter.BWDuplexSheets|PrintUsageC
ounter.ColorDuplexSheets|PrintUsageCounter.BWReverseSheets|PrintUsageCounter.Col
orReverseSheets|PrintUsageCounter.BWLargeSheets|PrintUsageCounter.ColorLargeShee
ts|DiagPrintUsageCounter.BWImpressions|DiagPrintUsageCounter.ColorImpressions|Di
agPrintUsageCounter.BWSheets|DiagPrintUsageCounter.ColorSheets|DiagPrintUsageCou
nter.BWLargeSheets|DiagPrintUsageCounter.ColorLargeSheets|CopyUsageCounter.BWImp
ressions|CopyUsageCounter.ColorImpressions|CopyUsageCounter.BW2upImpressions|Cop
yUsageCounter.Color2upImpressions|CopyUsageCounter.BWNupImpressions|CopyUsageCou
nter.ColorNupImpressions|CopyUsageCounter.BWSheets|CopyUsageCounter.ColorSheets|
CopyUsageCounter.BWDuplexSheets|CopyUsageCounter.ColorDuplexSheets|CopyUsageCoun
ter.BWReverseSheets|CopyUsageCounter.ColorReverseSheets|CopyUsageCounter.BWLarge
Sheets|CopyUsageCounter.ColorLargeSheets|ReportUsageCounter.BWImpressions|Report
UsageCounter.ColorImpressions|ReportUsageCounter.BWSheets|ReportUsageCounter.Col
orSheets|ReportUsageCounter.BWDuplexSheets|ReportUsageCounter.ColorDuplexSheets|
ReportUsageCounter.BWReverseSheets|ReportUsageCounter.ColorReverseSheets|ReportU
sageCounter.BWLargeSheets|ReportUsageCounter.ColorLargeSheets|LargeSizeUsageCoun
ter.BWImpressions|LargeSizeUsageCounter.ColorImpressions|PaperSizeUsageCounter.A
4|PaperSizeUsageCounter.UNSPECIFIED|FAXUsageCounter.SendCount0|FAXUsageCounter.S
endCount1|FAXUsageCounter.SendCount2|FAXUsageCounter.SendCount3|FAXUsageCounter.
SendCount4|FAXUsageCounter.SendCount5|FAXUsageCounter.SendImpressions0|FAXUsageC
ounter.SendImpressions1|FAXUsageCounter.SendImpressions2|FAXUsageCounter.SendImp
ressions3|FAXUsageCounter.SendImpressions4|FAXUsageCounter.SendImpressions5|FAXU
sageCounter.PrintBW2upImpressions|FAXUsageCounter.BW1ImpressionJob|FAXUsageCount
er.BW2ImpressionsJob|FAXUsageCounter.BW3ImpressionsJob|FAXUsageCounter.BW4Impres
sionsJob|FAXUsageCounter.BW5ImpressionsJob|FAXUsageCounter.BW6ImpressionsJob|FAX
UsageCounter.BW7ImpressionsJob|FAXUsageCounter.BW8ImpressionsJob|FAXUsageCounter
.BW9ImpressionsJob|FAXUsageCounter.BW10To19ImpressionsJob|FAXUsageCounter.BW20To
29ImpressionsJob|FAXUsageCounter.BW30To49ImpressionsJob|FAXUsageCounter.BW50To74
ImpressionsJob|FAXUsageCounter.BW75To99ImpressionsJob|FAXUsageCounter.BW100To249
ImpressionsJob|FAXUsageCounter.BWOver250ImpressionsJob|FAXUsageCounter.TotalTime
Sent0|FAXUsageCounter.TotalTimeSent1|FAXUsageCounter.TotalTimeSent2|FAXUsageCoun
ter.TotalTimeSent3|FAXUsageCounter.TotalTimeSent4|FAXUsageCounter.TotalTimeSent5
|FAXUsageCounter.TotalTimeReceived0|FAXUsageCounter.TotalTimeReceived1|FAXUsageC
ounter.TotalTimeReceived2|FAXUsageCounter.TotalTimeReceived3|FAXUsageCounter.Tot
alTimeReceived4|FAXUsageCounter.TotalTimeReceived5|IFAXUsageCounter.Print2upImpr
essions|IFAXUsageCounter.BW1ImpressionJob|IFAXUsageCounter.BW2ImpressionsJob|IFA
XUsageCounter.BW3ImpressionsJob|IFAXUsageCounter.BW4ImpressionsJob|IFAXUsageCoun
ter.BW5ImpressionsJob|IFAXUsageCounter.BW6ImpressionsJob|IFAXUsageCounter.BW7Imp
ressionsJob|IFAXUsageCounter.BW8ImpressionsJob|IFAXUsageCounter.BW9ImpressionsJo
b|IFAXUsageCounter.BW10To19ImpressionsJob|IFAXUsageCounter.BW20To29ImpressionsJo
b|IFAXUsageCounter.BW30To49ImpressionsJob|IFAXUsageCounter.BW50To74ImpressionsJo
b|IFAXUsageCounter.BW75To99ImpressionsJob|IFAXUsageCounter.BW100To249Impressions
Job|IFAXUsageCounter.BWOver250ImpressionsJob|DirectFAXUsageCounter.SendCount0|Di
rectFAXUsageCounter.SendCount1|DirectFAXUsageCounter.SendCount2|DirectFAXUsageCo
unter.SendCount3|DirectFAXUsageCounter.SendCount4|DirectFAXUsageCounter.SendCoun
t5|DirectFAXUsageCounter.SendImpressions0|DirectFAXUsageCounter.SendImpressions1
|DirectFAXUsageCounter.SendImpressions2|DirectFAXUsageCounter.SendImpressions3|D
irectFAXUsageCounter.SendImpressions4|DirectFAXUsageCounter.SendImpressions5|Pri
ntUsageCounter.BW2upSimplexImpressions|PrintUsageCounter.Color2upSimplexImpressi
ons|PrintUsageCounter.BW2upDuplexImpressions|PrintUsageCounter.Color2upDuplexImp
ressions|PrintUsageCounter.BW4upSimplexImpressions|PrintUsageCounter.Color4upSim
plexImpressions|PrintUsageCounter.BW4upDuplexImpressions|PrintUsageCounter.Color
4upDuplexImpressions|PrintUsageCounter.BWNupSimplexImpressions|PrintUsageCounter
.ColorNupSimplexImpressions|PrintUsageCounter.BWNupDuplexImpressions|PrintUsageC
ounter.ColorNupDuplexImpressions|PrintUsageCounter.BW1ImpressionJob|PrintUsageCo
unter.BW2ImpressionsJob|PrintUsageCounter.BW3ImpressionsJob|PrintUsageCounter.BW
4ImpressionsJob|PrintUsageCounter.BW5ImpressionsJob|PrintUsageCounter.BW6Impress
ionsJob|PrintUsageCounter.BW7ImpressionsJob|PrintUsageCounter.BW8ImpressionsJob|
PrintUsageCounter.BW9ImpressionsJob|PrintUsageCounter.BW10To19ImpressionsJob|Pri
ntUsageCounter.BW20To29ImpressionsJob|PrintUsageCounter.BW30To49ImpressionsJob|P
rintUsageCounter.BW50To74ImpressionsJob|PrintUsageCounter.BW75To99ImpressionsJob
|PrintUsageCounter.BW100To249ImpressionsJob|PrintUsageCounter.BWOver250Impressio
nsJob|PrintUsageCounter.Color1ImpressionJob|PrintUsageCounter.Color2ImpressionsJ
ob|PrintUsageCounter.Color3ImpressionsJob|PrintUsageCounter.Color4ImpressionsJob
|PrintUsageCounter.Color5ImpressionsJob|PrintUsageCounter.Color6ImpressionsJob|P
rintUsageCounter.Color7ImpressionsJob|PrintUsageCounter.Color8ImpressionsJob|Pri
ntUsageCounter.Color9ImpressionsJob|PrintUsageCounter.Color10To19ImpressionsJob|
PrintUsageCounter.Color20To29ImpressionsJob|PrintUsageCounter.Color30To49Impress
ionsJob|PrintUsageCounter.Color50To74ImpressionsJob|PrintUsageCounter.Color75To9
9ImpressionsJob|PrintUsageCounter.Color100To249ImpressionsJob|PrintUsageCounter.
ColorOver250ImpressionsJob|CopyUsageCounter.BW2upSimplexImpressions|CopyUsageCou
nter.Color2upSimplexImpressions|CopyUsageCounter.BW2upDuplexImpressions|CopyUsag
eCounter.Color2upDuplexImpressions|CopyUsageCounter.BW4upSimplexImpressions|Copy
UsageCounter.Color4upSimplexImpressions|CopyUsageCounter.BW4upDuplexImpressions|
CopyUsageCounter.Color4upDuplexImpressions|CopyUsageCounter.BWNupSimplexImpressi
ons|CopyUsageCounter.ColorNupSimplexImpressions|CopyUsageCounter.BWNupDuplexImpr
essions|CopyUsageCounter.ColorNupDuplexImpressions|CopyUsageCounter.BWSimplexToD
uplexSheets|CopyUsageCounter.ColorSimplexToDuplexSheets|CopyUsageCounter.BWDuple
xToDuplexSheets|CopyUsageCounter.ColorDuplexToDuplexSheets|CopyUsageCounter.BWSi
mplexToSimplexSheets|CopyUsageCounter.ColorSimplexToSimplexSheets|CopyUsageCount
er.BWDuplexToSimplexSheets|CopyUsageCounter.ColorDuplexToSimplexSheets|CopyUsage
Counter.BW1ImpressionJob|CopyUsageCounter.BW2ImpressionsJob|CopyUsageCounter.BW3
ImpressionsJob|CopyUsageCounter.BW4ImpressionsJob|CopyUsageCounter.BW5Impression
sJob|CopyUsageCounter.BW6ImpressionsJob|CopyUsageCounter.BW7ImpressionsJob|CopyU
sageCounter.BW8ImpressionsJob|CopyUsageCounter.BW9ImpressionsJob|CopyUsageCounte
r.BW10To19ImpressionsJob|CopyUsageCounter.BW20To29ImpressionsJob|CopyUsageCounte
r.BW30To49ImpressionsJob|CopyUsageCounter.BW50To74ImpressionsJob|CopyUsageCounte
r.BW75To99ImpressionsJob|CopyUsageCounter.BW100To249ImpressionsJob|CopyUsageCoun
ter.BWOver250ImpressionsJob|CopyUsageCounter.Color1ImpressionJob|CopyUsageCounte
r.Color2ImpressionsJob|CopyUsageCounter.Color3ImpressionsJob|CopyUsageCounter.Co
lor4ImpressionsJob|CopyUsageCounter.Color5ImpressionsJob|CopyUsageCounter.Color6
ImpressionsJob|CopyUsageCounter.Color7ImpressionsJob|CopyUsageCounter.Color8Impr
essionsJob|CopyUsageCounter.Color9ImpressionsJob|CopyUsageCounter.Color10To19Imp
ressionsJob|CopyUsageCounter.Color20To29ImpressionsJob|CopyUsageCounter.Color30T
o49ImpressionsJob|CopyUsageCounter.Color50To74ImpressionsJob|CopyUsageCounter.Co
lor75To99ImpressionsJob|CopyUsageCounter.Color100To249ImpressionsJob|CopyUsageCo
unter.ColorOver250ImpressionsJob|CopyUsageCounter.BW1OriginalJob|CopyUsageCounte
r.BW2OriginalsJob|CopyUsageCounter.BW3OriginalsJob|CopyUsageCounter.BW4Originals
Job|CopyUsageCounter.BW5OriginalsJob|CopyUsageCounter.BW6OriginalsJob|CopyUsageC
ounter.BW7OriginalsJob|CopyUsageCounter.BW8OriginalsJob|CopyUsageCounter.BW9Orig
inalsJob|CopyUsageCounter.BW10To19OriginalsJob|CopyUsageCounter.BW20To29Original
sJob|CopyUsageCounter.BW30To49OriginalsJob|CopyUsageCounter.BW50To74OriginalsJob
|CopyUsageCounter.BW75To99OriginalsJob|CopyUsageCounter.BW100To249OriginalsJob|C
opyUsageCounter.BWOver250OriginalsJob|CopyUsageCounter.Color1OriginalJob|CopyUsa
geCounter.Color2OriginalsJob|CopyUsageCounter.Color3OriginalsJob|CopyUsageCounte
r.Color4OriginalsJob|CopyUsageCounter.Color5OriginalsJob|CopyUsageCounter.Color6
OriginalsJob|CopyUsageCounter.Color7OriginalsJob|CopyUsageCounter.Color8Original
sJob|CopyUsageCounter.Color9OriginalsJob|CopyUsageCounter.Color10To19OriginalsJo
b|CopyUsageCounter.Color20To29OriginalsJob|CopyUsageCounter.Color30To49Originals
Job|CopyUsageCounter.Color50To74OriginalsJob|CopyUsageCounter.Color75To99Origina
lsJob|CopyUsageCounter.Color100To249OriginalsJob|CopyUsageCounter.ColorOver250Or
iginalsJob|PaperSizeUsageCounter.A3|PaperTrayUsageCounter.Tray1PrintedSheets|Pap
erTrayUsageCounter.Tray2PrintedSheets|PaperTrayUsageCounter.Tray3PrintedSheets|P
aperTrayUsageCounter.Tray4PrintedSheets|PaperTrayUsageCounter.Tray5PrintedSheets
|PaperTrayUsageCounter.Tray6PrintedSheets|PaperTrayUsageCounter.Tray7PrintedShee
ts|PaperTrayUsageCounter.Tray8PrintedSheets|PaperTrayUsageCounter.Tray1PrintedIm
pressions|PaperTrayUsageCounter.Tray2PrintedImpressions|PaperTrayUsageCounter.Tr
ay3PrintedImpressions|PaperTrayUsageCounter.Tray4PrintedImpressions|PaperTrayUsa
geCounter.Tray5PrintedImpressions|PaperTrayUsageCounter.Tray6PrintedImpressions|
PaperTrayUsageCounter.Tray7PrintedImpressions|PaperTrayUsageCounter.Tray8Printed
Impressions|StoredDocumentUsageCounter.UnprintedDeletedImpressions|UptimeUsageCo
unter.WarmUpTime|UptimeUsageCounter.IOTRunTime|UptimeUsageCounter.IITRunTime|Upt
imeUsageCounter.LowPowerTime|UptimeUsageCounter.SleepTime|UptimeUsageCounter.Sta
ndbyTime|UptimeUsageCounter.PowerOffTime
============= Line 3 =================
3|ABCDEF|110139|ABC|2010-09-24T12:32:00+09:00|2010-09-24T12:32:28+09:00|||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||0|0|0|0|0|0|0|0|0|0|0|0|0|
309|159|158|16|0|0|151|129|0|0|4709|2105|1971|704|2|0|2760|1407|1877|769|0|0|47|
86|0|0|0|0|0|0|305|21|1|0|0|0|204|18|101|3|0|0|1|1|60|0|51|0|9|0|0|0|0|0|77|92|4
309|0|0|5|0|0|0|0|0|19|0|0|0|0|0|1|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|355|0|0|0|0|0
|319|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|21|10|195
0|694|0|0|2|0|0|0|2|0|422|292|60|38|24|18|18|26|8|60|34|20|3|0|0|0|233|138|36|30
|10|20|9|11|7|27|17|6|2|1|0|0|1|0|0|0|0|0|0|0|0|0|0|0|5|1|96|2|103|15|0|0|84|7|0
|4|1|0|0|0|0|0|1|0|0|0|1|0|13|4|0|0|0|0|0|0|0|0|0|0|0|0|0|0|80|12|0|3|1|0|0|0|0|
1|0|0|1|0|0|0|14|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|135|3631|658|11|135|9|0|0|0|5901|
1114|11|169|9|0|0|0|0|66|513|29|5715|102714|11941|28
============= Line 4 =================
3|ABCDEF|110139|ABC|2010-09-24T13:34:00+09:00|2010-09-24T13:34:16+09:00|0|0|0|0|
0|0|0|0|0|0|0|0|0|0|5|19|0|6|0|0|0|0|0|4|0|0|0|0|0|4|0|0|0|0|0|0|4|0|0|0|0|0|0|0
|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|309|159|158|16|0|
0|151|129|0|0|4709|2105|1971|704|2|0|2760|1407|1877|769|0|0|47|86|0|0|0|0|0|0|30
5|21|1|0|0|0|204|18|101|3|0|0|1|1|60|0|51|0|9|0|0|0|0|0|77|92|4309|0|0|5|0|0|0|0
|0|19|0|0|0|0|0|1|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|355|0|0|0|0|0|319|0|0|0|0|0|0|
0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|21|10|1950|694|0|0|2|0|0|0
|2|0|422|292|60|38|24|18|18|26|8|60|34|20|3|0|0|0|233|138|36|30|10|20|9|11|7|27|
17|6|2|1|0|0|1|0|0|0|0|0|0|0|0|0|0|0|5|1|96|2|103|15|0|0|84|7|0|4|1|0|0|0|0|0|1|
0|0|0|1|0|13|4|0|0|0|0|0|0|0|0|0|0|0|0|0|0|80|12|0|3|1|0|0|0|0|1|0|0|1|0|0|0|14|
3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|135|3631|658|11|135|9|0|0|0|5901|1114|11|169|9|0|0
|0|0|66|513|29|5730|102741|11960|28
============= Line 5 =================
4|2010-09-25T02:00:24+09:00|2
PL/SQL procedure successfully completed.
SQL> Error you are getting is not file related. It simply tells line you read from file is too big to be displayed by DBMS_OUTPUT.PUT_LINE, which tells me you are on some older Oracle version. My test was conducted on 10.2.0.4.0. Try issuing SET SERVEROUTPUT ON SIZE 1000000 befor running your code.
SY. -
Hi
We are writting the file through UTL utility and 1st we are writing the HEADER of report and then from next line we are writing the data.But when we are try to execute the procedure its override the header part and wriitng the data only,But i need to write both the header and after header it need to write the data from the next line.
Please help ASAP.
Regards
DasCREATE OR REPLACE PROCEDURE APPS.print_reports
IS
wfile_handle UTL_FILE.file_type;
v_wstring VARCHAR2 (100);
v_file VARCHAR2 (100);
v_date VARCHAR2 (20);
mail_conn UTL_SMTP.connection;
l_rep_headers VARCHAR2 (32000);
p_o_srv_result xxcss_prf_report_pkg.ref_cur_srv_prog;
lv_str_type XXCSS_PRF_STRING;
l_line VARCHAR2 (32000);
lv_send_to VARCHAR2 (200);
lv_host_name VARCHAR2 (200) := 'outbound.yahoo.com';
l_vtab CHAR := CHR (9);
lv_from VARCHAR2 (200) := '[email protected]';
lv_att_file_name VARCHAR2 (200);
v_path VARCHAR2 (200);
v_instance VARCHAR2 (200);
p_request_type VARCHAR2 (1) := 'E';
p_request_id NUMBER;
errbuf VARCHAR2 (2000);
retcode NUMBER;
-- lv_from VARCHAR2(2000) := '[email protected]';
crlf VARCHAR2 (2) := CHR (13) || CHR (10);
namesfile UTL_FILE.FILE_TYPE;
lv_line_data VARCHAR2 (32000);
BEGIN
BEGIN
SELECT VALUE
INTO v_path
FROM v$parameter
WHERE NAME = 'utl_file_dir';
EXCEPTION
WHEN OTHERS
THEN
v_path := '\tmp';
END;
l_rep_headers :=
'REGION'
|| CHR (9)
|| 'COUNTRY'
|| CHR (9)
|| 'CUSTOMER NAME'
|| CHR (9)
|| 'ERP CUSTOMER NUMBER'
|| CHR (9)
|| 'PROFILE ID'
|| CHR (9);
FOR i IN ( SELECT DISTINCT srv_program_id srv_prgm
FROM xxcss_prf_cust_srv_programs
ORDER BY srv_program_id ASC)
LOOP
l_rep_headers := l_rep_headers ||i.srv_prgm || CHR (9);
END LOOP;
-- l_rep_headers := l_rep_headers || CHR (13);
BEGIN
XXCSS_PRF_REPORT_PKG.offline_daemon (p_request_id,
p_request_type,
p_o_srv_result,
errbuf,
retcode);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE ('Error in Offline');
END;
IF UTL_FILE.is_open (wfile_handle)
THEN
UTL_FILE.fclose (wfile_handle);
END IF;
BEGIN
lv_att_file_name := 'Eligibility_reports'||p_request_id||'.csv';
DBMS_OUTPUT.PUT_LINE ('header '||l_rep_headers);
wfile_handle := UTL_FILE.fopen (v_path, lv_att_file_name, 'W');
--UTL_FILE.put_line (wfile_handle, 'Test');
UTL_FILE.put_line (wfile_handle, l_rep_headers);
LOOP
--DBMS_OUTPUT.PUT_LINE ('loop start');
FETCH p_o_srv_result INTO lv_str_type;
EXIT WHEN p_o_srv_result%NOTFOUND;
l_line := NULL;
FOR i IN 1 .. lv_str_type.COUNT
LOOP
l_line := l_line || lv_str_type (i) || CHR (9);
UTL_FILE.put_line (wfile_handle, l_line);
END LOOP;
-- UTL_FILE.put_line (wfile_handle, l_line);
--DBMS_OUTPUT.PUT_LINE ('loop end ' || l_line);
END LOOP;
UTL_FILE.fflush (wfile_handle);
UTL_FILE.fclose (wfile_handle);
exception
when others then
DBMS_OUTPUT.PUT_LINE ('error is ' || sqlerrm);
END;
lv_str_type.DELETE;
BEGIN
SELECT instance_name
INTO v_instance
FROM v$instance
WHERE ROWNUM < 2;
EXCEPTION
WHEN OTHERS
THEN
v_instance := NULL;
END;
BEGIN
wfile_handle := UTL_FILE.FOPEN (v_path, lv_att_file_name, 'R');
LOOP
UTL_FILE.GET_LINE (wfile_handle, lv_line_data);
DBMS_OUTPUT.PUT_LINE (lv_line_data);
lv_line_data := lv_line_data || crlf || lv_line_data;
END LOOP;
UTL_FILE.FCLOSE (wfile_handle);
EXCEPTION
WHEN OTHERS
THEN
UTL_FILE.FCLOSE (wfile_handle); -- close file
NULL;
END;
SELECT email_id
INTO lv_send_to
FROM xxcss_prf_offline_report_tb
WHERE request_id = p_request_id AND report_type = p_request_type;
mail_conn := UTL_SMTP.open_connection (lv_host_name, 25);
UTL_SMTP.Helo (mail_conn, lv_host_name);
UTL_SMTP.Mail (mail_conn, 'sangrdas');
UTL_SMTP.Rcpt (mail_conn, lv_send_to);
UTL_SMTP.Data (
Mail_Conn,
'Date: '
|| TO_CHAR (SYSDATE, 'Dy, DD Mon YYYY hh24:mi:ss')
|| crlf
|| 'From: '
|| lv_from
|| crlf
|| 'Subject: ELIGIILITY Report_'
|| p_request_id
|| crlf
|| 'To: '
|| lv_send_to
|| crlf
|| 'MIME-Version: 1.0'
|| crlf
|| -- Use MIME mail standard
'Content-Type: multipart/mixed;'
|| crlf
|| ' boundary="-----SECBOUND"'
|| crlf
|| '-------SECBOUND'
|| crlf
|| 'Content-Type: text/plain;'
|| crlf
|| 'Content-Transfer_Encoding: 7bit'
|| crlf
|| 'some message text'
|| crlf
|| -- Message body
'more message text'
|| crlf
|| '-------SECBOUND'
|| crlf
|| 'Content-Type: text/plain;'
|| crlf
|| ' name="'|| lv_att_file_name||'"'
|| crlf
|| 'Content-Transfer_Encoding: 8bit'
|| crlf
|| 'Content-Disposition: attachment;'
|| crlf
|| ' filename="'
|| lv_att_file_name
|| '"'
|| crlf
|| lv_line_data
|| crlf
|| -- Content of attachment
crlf
|| '-------SECBOUND--' -- End MIME mail
UTL_SMTP.quit (mail_conn);
END print_reports;
/ -
Problems with moving files to ora directory UTL_FILE.PUT_RAW - ORA-29285
hi,
i'm using apex 4.1
i have a procedure which moves my file from apex_application_files to ORA directory.
if i choose a text file or small word document which is 1kb, it works. but if i have pdf file (85kb) or word document (16kb) it gives me ORA-29285: file write error
what's my problem?
PROCEDURE put_file_to_server (p_filename IN VARCHAR2,p_cert_type IN VARCHAR2,p_cert_pk IN NUMBER)
AS
l_file UTL_FILE.file_type;
l_blob_len INTEGER;
l_pos INTEGER := 1;
l_amount BINARY_INTEGER := 32767;
l_buffer RAW (32767);
v_new_filename VARCHAR2(100);
v_bfile BFILE ;
BEGIN
-- delete from apex_application_files;
--Neuen Dateinamen generieren
v_new_filename := p_cert_type||'_'||p_cert_pk;
v_bfile := BFILENAME (v_directory, v_new_filename);
--Datei erstellen
l_file := UTL_FILE.fopen(v_directory,v_new_filename,'w');
IF DBMS_LOB.FILEEXISTS (v_bfile) = 1 THEN
cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'File exists');
FOR rec IN (select blob_content lblob from apex_application_files where rownum = 1)
LOOP
l_blob_len := DBMS_LOB.getlength(rec.lblob);
cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Filesize is '||l_blob_len);
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.read (rec.lblob, l_amount, l_pos, l_buffer);
UTL_FILE.put_raw (l_file, l_buffer, FALSE);
l_pos := l_pos + l_amount;
END LOOP;
COMMIT;
END LOOP;
--Datei schließen
UTL_FILE.fclose(l_file);
else
cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Datei doesn't exist');
end if;
EXCEPTION
WHEN OTHERS
THEN
-- Close the file if something goes wrong.
IF UTL_FILE.is_open (l_file) THEN
UTL_FILE.fclose (l_file);
END IF;
delete from apex_application_files;
RAISE;
delete from apex_application_files;
END put_file_to_server;Sorry but din't test this...Can you give it a try and see if this works?
PROCEDURE put_file_to_server(
p_filename IN VARCHAR2,
p_cert_type IN VARCHAR2,
p_cert_pk IN NUMBER)
AS
l_file UTL_FILE.file_type;
l_blob_len INTEGER;
l_pos INTEGER := 1;
l_amount BINARY_INTEGER := 32767;
l_buffer RAW (32767);
v_new_filename VARCHAR2(100);
v_bfile BFILE ;
vblob BLOB;
vstart NUMBER := 1;
my_vr RAW(32000);
bytelen NUMBER := 32000;
LEN NUMBER;
BEGIN
-- delete from apex_application_files;
--Neuen Dateinamen generieren
v_new_filename := p_cert_type||'_'||p_cert_pk;
v_bfile := BFILENAME (v_directory, v_new_filename);
--Datei erstellen
--l_file := UTL_FILE.fopen(v_directory,v_new_filename,'w');
l_file := UTL_FILE.fopen(v_directory,v_new_filename, 'WB', 32760);
IF DBMS_LOB.FILEEXISTS (v_bfile) = 1 THEN
cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'File exists');
FOR rec IN
(SELECT blob_content lblob,
LENGTH(blob_content) LEN
FROM apex_application_files
WHERE rownum = 1
LOOP
cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Filesize is '|| LEN);
IF LEN < 32760 THEN
utl_file.put_raw(l_file,lblob);
utl_file.fflush(l_file);
ELSE -- write in pieces
vstart := 1;
WHILE vstart < LEN
LOOP
dbms_lob.read(vblob,bytelen,vstart,my_vr);
utl_file.put_raw(l_file,my_vr);
utl_file.fflush(l_file);
-- set the start position for the next cut
vstart := vstart + bytelen;
-- set the end position if less than 32000 bytes
x := x - bytelen;
IF x < 32000 THEN
bytelen := x;
END IF;
END LOOP;
END IF;
END LOOP;
ELSE
cert_log_pkg.m(p_module => 'CERT_FILE_PKG.PUT_FILE_TO_SERVER',p_msg => 'Datei doesnt exist');
END IF;
utl_file.fclose(l_file);
EXCEPTION
WHEN OTHERS THEN
-- Close the file if something goes wrong.
IF UTL_FILE.is_open (l_file) THEN
UTL_FILE.fclose (l_file);
END IF;
DELETE FROM apex_application_files;
RAISE;
DELETE FROM apex_application_files;
END put_file_to_server;Edited by: Vitor Rodrigues on 17/Fev/2012 12:03 -
Help in my pl/sql from blob to a file
i found the code here: http://www.oracle-base.com/articles/9i/ExportBlob9i.php but somehow i was confused by errors:
CREATE OR REPLACE
procedure sp_readBlob
declare
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
-- Get LOB locator
SELECT fileupload
INTO l_blob
FROM rsmaster
WHERE rownum = 1;
l_blob_len := DBMS_LOB.getlength(l_blob);
-- Open the destination file.
l_file := UTL_FILE.fopen('BLOBS','MyImage.gif','w', 32767);
-- Read chunks of the BLOB and write them to the file
-- until complete.
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
-- Close the file.
UTL_FILE.fclose(l_file);
EXCEPTION
WHEN OTHERS THEN
-- Close the file if something goes wrong.
IF UTL_FILE.is_open(l_file) THEN
UTL_FILE.fclose(l_file);
END IF;
RAISE;
END;
Error(2,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: ( ; is with authid as cluster compress order using compiled wrapped external deterministic parallel_enable pipelined
Error(40): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
thanks in advance!You haven't used the quoted code very well!
That is an 'anonymous pl/sql block and uses the explicit DECLARE to define the area for declarations.
You are using a named pl/sql procedure and do not require the explicit DECLARE.
I think you must have miss-read the 'Create or replace Directory' line above. -
UTL_FILE.get_line won't read large files ?
I am trying to read a large fixed length flat file. If I cut the file down to really small it will read it but it reads it as a single line. If I try to read a larger file > 32k I get a READ_ERROR. I am pretty sure it has to do with the end of line marker but I saw nothing about that in the UTL_FILE documentation. This is on UNIX, new line character after each record in the file. Standard unix flat file.
Any ideas on what to do?
Thanks in advance
Matt
[email protected]
my code:
BEGIN
BEGIN
std_file := UTL_FILE.FOPEN('&4','&1','r',32767);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20011,'Invalid Path for STD file, &4/&1');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20014,'Other Error trying to open STD file, &4/&1');
END;
IF UTL_FILE.is_open(std_file) = FALSE THEN
RAISE_APPLICATION_ERROR(-20015,'Could not open STD file, &4/&1');
END IF;
-- READ STD FILE HEADER
BEGIN
UTL_FILE.get_line(std_file,hdr_text);
EXCEPTION
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
RAISE_APPLICATION_ERROR(-20017,'STD read file handle not valid');
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20018,'STD read invalid operation error');
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR(-20019,'STD read error');
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20020,'STD read no data found');
WHEN VALUE_ERROR THEN
RAISE_APPLICATION_ERROR(-20021,'STD read value error');
END;
-- PROCESS TRANSACTIONS
LOOP
BEGIN
tran_text := NULL;
UTL_FILE.get_line(std_file,tran_text);
EXCEPTION
WHEN no_data_found THEN EXIT; -- EOF
WHEN value_error THEN
RAISE_APPLICATION_ERROR(-20010,'STD record too long.');
END;
std_rowcount := std_rowcount + 1;
END LOOP;
UTL_FILE.FCLOSE(std_file);
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20001,'No Data Found.');
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20002,'Invalid Path ');
WHEN UTL_FILE.INVALID_MODE THEN
RAISE_APPLICATION_ERROR(-20003,'Invalid Mode ');
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20004,'Invalid Operation ');
END;
nullWe are still hung up on this. I tried implementing the code from STEVE'S XML book but still haven't resovled it.
The clob is being created via XSU see below. The new char[8192] appeasr to force the output file to 8K
with trailing characters on small clobs but adds a carraige return each 8K on larger ones.
As usual any input is appreciated from all. Doese anyone know of a good JAVA forum like this one?
Thanks
PROCEDURE BuildXml(v_return OUT INTEGER, v_message OUT VARCHAR2,string_in VARCHAR2,xml_CLOB OUT NOCOPY CLOB) IS
queryCtx DBMS_XMLquery.ctxType;
Buffer RAW(1024);
Amount BINARY_INTEGER := 1024;
Position INTEGER := 1;
sql_string VARCHAR2(2000) := string_in;
BEGIN
v_return := 1;
v_message := 'BuildXml completed succesfully.';
queryCtx := DBMS_XMLQuery.newContext(sql_string);
xml_CLOB := DBMS_XMLQuery.getXML(queryCtx);
DBMS_XMLQuery.closeContext(queryCtx);
EXCEPTION WHEN OTHERS THEN
v_return := 0;
v_message := 'BuildXml failed - '||SQLERRM;
END BuildXml;
create or replace and compile java source named sjs.write_CLOB as
import java.io.*;
import java.sql.*;
import java.math.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class write_CLOB extends Object
public static void pass_str_array(oracle.sql.CLOB p_in,java.lang.String f_in)
throws java.sql.SQLException, IOException
File target = new File(f_in);
FileWriter fw = new FileWriter(target);
BufferedWriter out = new BufferedWriter(fw);
Reader is = p_in.getCharacterStream();
char buffer[] = new char[8192];
int length;
while( (length=is.read(buffer)) != -1) {
out.write(buffer);
is.close();
fw.close();
/ -
Utl_file how to start reading from a certain position?
Hi all,
i'm currently using utl_file to read a text file and import to db. i have managed to do it. however i would like to avoid reading the first line as it is the header. i would also like to avoid the last line as it is the footer.
how do i use the function of get line to start reading at a certain position? i am also able to get the length but i do not know how to make it start reading from a certain position.
the length of the first line will always be 9 and length for the last line would be 51.
here's my code so far:
set serveroutput on
declare
vSFile utl_file.file_type;
vNewLine VARCHAR2(4000);
file_name VARCHAR2(200) := 'read.txt';
v_exist BOOLEAN;
v_length number;
blocksize NUMBER;
temp_value varchar2 (4000);
BEGIN
vSFile := utl_file.fopen('MYDIR', file_name,'r');
IF utl_file.is_open(vSFile) THEN
LOOP
BEGIN
utl_file.get_line(vSFile, vNewLine);
IF vNewLine IS NULL THEN
EXIT;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
UTL_FILE.FGETATTR('MYDIR',file_name,v_exist,v_length,blocksize);
dbms_output.put_line(v_length);
COMMIT;
END IF;
utl_file.fclose(vSFile);
END read_demo;Hi,
utl_file has an fseek procedure for moving the file pointer around in a file, either absolute or relative number of bytes.
It's in the documentation, I'm surprised you didn't see it there when you looked before going to the hassle of asking us a question.
Andre
Maybe you are looking for
-
How to write ICONS in ALV TOP of Page
Hai experts, How to ICON in ALV Top of PAGE i want to wrire ICON_LED_RED for cancellation Invioce ICON_LED_GREEN for Invioce but i pass this values to wa_header-info it comes @5C@ @5B@ thanks sitaram
-
File to RFC synchronous scenario stopped Picking the files
Hi Experts, We have a File to RFC synchronous scenario. Till yesterday night it is working fine. But suddenly it is stooped working.In moni, i can see the failed messages with the Mapping error " Can not create target element, values missing in the q
-
I am runing 10.8.2 and for the last few weeks when I make entries in my Contacts "notes section"; it does not save everything that was entered and I have to go back and repeat the process.
-
Just replaced yellow ink in Photosmart 5180 -- I'm sure its the right thing, its brand new and I shook it and some ink came out-- but printer insists there is no yellow ink. Ideas?
-
Where would be the best use of the internet to find DW CS5 classroom in book supplemantary CD files
Is the cd not available with missing manual? could it be possible to find the cd wiht out the book? Do I have to buy the book to get a cd of the files? Appreciation is everything?