Utl_file.write_error
I am using utl_file package in my pl/sql procedure to write to a .csv file on the network.
I have set my utL_file_dir in init.ora file.
When I execute the procedure, I am getting a write_error exception. I have checked the permissions and I have full access to the directory. I am using NT m/c.
If any of you ran into similar problems, please suggest a solution.
Thank you
null
Hi,
The Problem here is that UTL_FILE can only write to the Directory ON THE SERVER which has been identified with UTL_FILE_DIR.
Regards,
Ganesh R
Similar Messages
-
UTL_FILE write_error when writing large binary files to unix os
I am trying to write large files to a folder in unix from a table containing a BLOB object. The procedure below is called by another procedure I have written to do this. It works in windows environment fine with files up to 360MB. When I run this exact same procedure in UNIX I get an initialization error. When I change the WB in the fopen call to W it works. I can store all the files I want up to 130MB in size. The next size larger file I have is 240MB and it fails after writing the first 1KB passing the utl_file.write_error message. If someone can help me to diagnose the problem, I would really appreciate it. i have been trying everything I can think of to get this to work.
Specifics are, the windows version is 10GR2, on unix we are running on Sun Solaris 9 using 9iR2
PROCEDURE writebin(pi_file_name IN VARCHAR2, pi_file_url IN VARCHAR2, pi_file_data IN BLOB)
IS
v_file_ref utl_file.file_type;
v_lob_size NUMBER;
v_raw_max_size constant NUMBER := 32767;
v_buffer raw(32767);
v_buffer_offset NUMBER := 1;
-- Position in stream
v_buffer_length NUMBER;
BEGIN
-- WB used in windows environment. W used in unix
v_lob_size := dbms_lob.getlength(pi_file_data);
v_file_ref := utl_file.fopen(pi_file_url, pi_file_name, 'WB', v_raw_max_size);
v_buffer_length := v_raw_max_size;
WHILE v_buffer_offset < v_lob_size
LOOP
IF v_buffer_offset + v_raw_max_size > v_lob_size THEN
v_buffer_length := v_lob_size -v_buffer_offset;
END IF;
dbms_lob.READ(pi_file_data, v_buffer_length, v_buffer_offset, v_buffer);
utl_file.put_raw(v_file_ref, v_buffer, TRUE);
v_buffer_offset := v_buffer_offset + v_buffer_length;
END LOOP;
utl_file.fclose(v_file_ref);
END writebin;
Message was edited by:
user599879check if this cample code helps -
CREATE OR REPLACE PROCEDURE prc_unload_blob_to_file IS
vlocation VARCHAR2(16) := ‘LOB_OUTPUT’;
vopen_mode VARCHAR2(16) := ‘w’;
bimax_linesize NUMBER := 32767;
v_my_vr RAW(32767);
v_start_pos NUMBER := 1;
v_output utl_file.file_type;
BEGIN
FOR cur_lob IN (SELECT vmime_type,
blob_resim,
vresim,
dbms_lob.getlength(blob_resim) len
FROM tcihaz_resim a
WHERE rownum < 3 -- for test purposes
ORDER BY a.nresim_id) LOOP
v_output := utl_file.fopen(vlocation,
cur_lob.vresim,
vopen_mode,
bimax_linesize);
dbms_output.put_line(’Column length: ‘ || to_char(cur_lob.len) || ‘ for file: ‘ ||
cur_lob.vresim);
v_start_pos := 1;
IF cur_lob.len < bimax_linesize THEN
dbms_lob.READ(cur_lob.blob_resim,
cur_lob.len,
v_start_pos,
v_my_vr);
utl_file.put_raw(v_output,
v_my_vr,
autoflush => TRUE);
dbms_output.put_line(’Finished Reading and Flushing ‘ || to_char(cur_lob.len) ||
‘ Bytes’ || ‘ for file: ‘ || cur_lob.vresim);
ELSE
dbms_lob.READ(cur_lob.blob_resim,
bimax_linesize,
v_start_pos,
v_my_vr);
utl_file.put_raw(v_output,
v_my_vr,
autoflush => TRUE);
dbms_output.put_line(’Finished Reading and Flushing ‘ || to_char(cur_lob.len) ||
‘ Bytes’ || ‘ for file: ‘ || cur_lob.vresim);
END IF;
v_start_pos := v_start_pos + bimax_linesize;
WHILE (v_start_pos < bimax_linesize) LOOP
-- loop till entire data is fetched
dbms_lob.READ(cur_lob.blob_resim,
bimax_linesize,
v_start_pos,
v_my_vr);
utl_file.put_raw(v_output,
v_my_vr,
autoflush => TRUE);
dbms_output.put_line(’Finished Reading and Flushing ‘ ||
to_char(bimax_linesize + v_start_pos - 1) || ‘ Bytes’ ||
‘ for file: ‘ || cur_lob.vresim);
v_start_pos := v_start_pos + bimax_linesize;
END LOOP;
utl_file.fclose(v_output);
dbms_output.put_line(’Finished successfully and file closed’);
END LOOP;
END prc_unload_blob_to_file;
set serveroutput on
set timing on
create or replace directory LOB_OUTPUT as ‘/export/home/oracle/tutema/’;
GRANT ALL ON DIRECTORY LOB_OUTPUT TO PUBLIC;
exec prc_unload_blob_to_file ;
Column length: 3330 for file: no_image_found.gif
Finished Reading and Flushing 3330 Bytes for file: no_image_found.gif
Finished successfully and file closed
Column length: 10223 for file: OT311.gif
Finished Reading and Flushing 10223 Bytes for file: OT311.gif
Finished successfully and file closed
PL/SQL procedure successfully completedWith 9iR2 PLSQL can write binary files using UTL_FILE put_raw function, prior to Oracle9iR2 you will need to create an external procedure with Java, C, VB or some 3gl language.
Some references -
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:6379798216275
Oracle® Database PL/SQL Packages and Types Reference 10g Release 2 (10.2)
UTL_FILE - http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14095
http://psoug.org/reference/dbms_lob.html
Metalink Note:70110.1, Subject: WRITING BLOB/CLOB/BFILE CONTENTS TO A FILE USING EXTERNAL PROCEDURES -
제품 : PL/SQL
작성날짜 : 2002-11-22
(8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
===================================================
Problem Description
PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
UTL_FILE.WRITE_ERROR
UTL_FILE.READ_ERROR
User-defined exception
8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
Default:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2)
RETURN file_type;
최대 라인 싸이즈를 지정하고자 할때:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
Solution Description:
MAX_LINESIZE 파라메터를 추가한 예이다.
CREATE OR REPLACE PROCEDURE file_test IS
file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
BEGIN
-- Open the same file to read from
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
-- Read a line from the file.
UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
-- Print fetched line out to the SQL*PLUS prompt.
DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
-- CLose the file.
UTL_FILE.FCLOSE(file_handle);
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no_data_found');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('other stuff');
UTL_FILE.FCLOSE(file_handle);
END;
아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
SQL> set serveroutput on
SQL> exec file_test
File size is : 1921
PL/SQL procedure successfully completed.
Reference Ducumment
<Note:1026951.6>
KOREAN Bulletin : 11532제품 : PL/SQL
작성날짜 : 2002-11-22
(8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
===================================================
Problem Description
PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
UTL_FILE.WRITE_ERROR
UTL_FILE.READ_ERROR
User-defined exception
8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
Default:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2)
RETURN file_type;
최대 라인 싸이즈를 지정하고자 할때:
FUNCTION fopen(location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
Solution Description:
MAX_LINESIZE 파라메터를 추가한 예이다.
CREATE OR REPLACE PROCEDURE file_test IS
file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
BEGIN
-- Open the same file to read from
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
-- Read a line from the file.
UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
-- Print fetched line out to the SQL*PLUS prompt.
DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
-- CLose the file.
UTL_FILE.FCLOSE(file_handle);
file_handle :=
UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
-- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no_data_found');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
UTL_FILE.FCLOSE(file_handle);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('other stuff');
UTL_FILE.FCLOSE(file_handle);
END;
아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
SQL> set serveroutput on
SQL> exec file_test
File size is : 1921
PL/SQL procedure successfully completed.
Reference Ducumment
<Note:1026951.6>
KOREAN Bulletin : 11532 -
hi all,
I am using Oracle XE and forms 6i and am facing the above error when i try to use the utl_file utility.
WHEN BUTTOn PRESSED
IF (:EXPORT_IMPORT_DATA = 'E') THEN
message(lc_status);
SECURITY.PKG_gen_trnsfr_data_flat_file.PROC_gen_trnsfr_data_flat_file(:DATA_FILE_PATH, :DATA_FILE_NAME, lc_status);
PKG_GEN_TRNSFR_DATA_FLAT_FILE body
create or replace PACKAGE BODY PKG_gen_trnsfr_data_flat_file IS
PROCEDURE proc_gen_trnsfr_data_flat_file(p_file_location IN VARCHAR2, p_file_name IN VARCHAR2, po_status OUT VARCHAR2) IS
lh_filename UTL_FILE.FILE_TYPE;
ls_data VARCHAR2(2000);
ln_count NUMBER;
lc_error VARCHAR2(10000);
CURSOR cur_FPM_DAMAGE_COMPENSATION IS SELECT RPAD(nvl(PDCO_CASE_CLASS,' '),1) || RPAD(nvl(PDCO_CASE_DISPOSAL_PENDING,' '),1) || RPAD(nvl(PDCO_CASE_DISPOSAL_TYPE,' '),1) || RPAD(nvl(PDCO_CC_NO,0),9) || RPAD(nvl(PDCO_CF_NO,0),9) || RPAD(nvl(PDCO_COMPEN_REALISED,0),18) || RPAD(nvl(PDCO_CONFISCATED_PRODUCE,' '),25) || RPAD(nvl(PDCO_CR_NO,0),9) || RPAD(nvl(PDCO_DAMAGE_DETAILS,' '),90) || RPAD(nvl(PDCO_DAMAGE_REPORT_NO,0),13) || RPAD(NVL(TO_CHAR(PDCO_DATE_ORDER_COMPOUNDING,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PDCO_DATE_PROSECUTION,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PDCO_DISPOSAL_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_DR_NO,0),9) || RPAD(nvl(PDCO_FOREST_NAME,' '),50) || RPAD(NVL(TO_CHAR(PDCO_ISSUE_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PDCO_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_NO_OF_PERSONS_IN_THE_CASE,0),6) || RPAD(nvl(PDCO_NO_ORDER_FOR_COMPOUNDING,' '),15) || RPAD(nvl(PDCO_OFFENCE_DETAILS,' '),90) || RPAD(nvl(PDCO_OFFENCE_TYPE,' '),1) || RPAD(nvl(PDCO_OFFENDER_ADDRESS,' '),90) || RPAD(nvl(PDCO_OFFENDER_NAME,' '),200) ||
RPAD(nvl(PDCO_OFFICIAL_NAME,' '),30) || RPAD(nvl(PDCO_RA_SIGN,' '),30) || RPAD(NVL(TO_CHAR(PDCO_RA_SIGN_DATE,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PDCO_RECEIPT_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PDCO_RR_NO,0),18) || RPAD(nvl(PDCO_TOOLS,0),18) || RPAD(nvl(PDCO_TOTAL,0),18) || RPAD(nvl(PDCO_VALUE_CONFISCATED_PROD,0),18) || RPAD(nvl(PDCO_VFP,0),18) || RPAD(nvl(PDCO_YDIV_DIVISION_CODE,' '),8) || RPAD(nvl(PDCO_YRAN_RANGE_CODE,' '),8) outstring FROM FPM_DAMAGE_COMPENSATION;
CURSOR cur_FPM_DAMAGE_COMPENSATION_R IS SELECT RPAD(nvl(CIRCLE,' '),90) || RPAD(nvl(DIVISION,' '),90) || RPAD(nvl(PREV_A,0),9) || RPAD(nvl(PREV_B,0),9) || RPAD(nvl(PREV_TOTAL,0),11) || RPAD(nvl(TOT_A,0),11) || RPAD(nvl(TOT_B,0),11) || RPAD(nvl(TOT_C,0),11) || RPAD(nvl(T_A,0),9) || RPAD(nvl(T_B,0),9) || RPAD(nvl(T_C,0),9) || RPAD(nvl(X_A,0),9) || RPAD(nvl(X_B,0),9) || RPAD(nvl(X_C,0),9) || RPAD(nvl(Y_A,0),9) || RPAD(nvl(Y_B,0),9) || RPAD(nvl(Y_C,0),9) || RPAD(nvl(Z_A,0),9) || RPAD(nvl(Z_B,0),9) || RPAD(nvl(Z_C,0),9) outstring FROM fpm.FPM_DAMAGE_COMPENSATION_R;
CURSOR cur_FPM_ENCROACHMENT IS SELECT RPAD(nvl(PENC_AREA_UNDER_ENCROACH,0),18) || RPAD(nvl(PENC_BALANCE_AREA_UN_ENC,0),18) || RPAD(nvl(PENC_ENCROACH_ID,' '),8) || RPAD(nvl(PENC_FOREST_NAME,' '),50) || RPAD(nvl(PENC_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PENC_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENC_LEGAL_STATUS_OF_FOREST,' '),90) || RPAD(NVL(TO_CHAR(PENC_PERIOD_FROM_UNDER_ENC,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENC_PRESENT_STATUS,' '),90) || RPAD(nvl(PENC_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_ENCROACHMENT;
CURSOR cur_FPM_ENCROACHMENT_REMOVALS IS SELECT RPAD(nvl(PENR_ACTION_TAKEN,' '),90) || RPAD(nvl(PENR_AREA_REMOVED_ENCMNT,0),18) || RPAD(NVL(TO_CHAR(PENR_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENR_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PENR_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PENR_PENC_ENCROACHMENT_ID,' '),8) || RPAD(nvl(PENR_PENC_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_ENCROACHMENT_REMOVALS;
CURSOR cur_FPM_FIRE IS SELECT RPAD(nvl(PFIR_ACTION_TAKEN,' '),90) || RPAD(nvl(PFIR_AREA_EFFECTED,0),18) || RPAD(nvl(PFIR_CAUSE_OF_FIRE,' '),2) || RPAD(nvl(REPLACE(REPLACE(PFIR_DAMAGE_DETAILS,CHR(13),' '),CHR(10),' '),' '),200) || RPAD(nvl(PFIR_DAMAGE_VALUE,0),18) || RPAD(NVL(TO_CHAR(PFIR_DATE_OF_FIRE,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PFIR_DATE_VISIT_DFO,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PFIR_DATE_VISIT_RANGEOFFICER,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PFIR_DFO_COMMENTS,' '),90) || RPAD(nvl(PFIR_DFO_SIGN,' '),30) || RPAD(NVL(TO_CHAR(PFIR_DFO_SIGN_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PFIR_FIRE_NO,' '),10) || RPAD(nvl(PFIR_FOREST_NAME,' '),50) || RPAD(nvl(PFIR_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PFIR_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PFIR_NO_OF_TREES,0),18) || RPAD(nvl(PFIR_QTY_OTH_FORST_PROD_BRNT,0),18) || RPAD(nvl(PFIR_RANGEOFFICER_COMMENTS,' '),90) || RPAD(nvl(PFIR_REPORTING_PERSON,' '),30) || RPAD(nvl(PFIR_VALUE_OTH_FORST_PROD_BRNT,0),18) || RPAD(nvl(PFIR_VALUE_TREES_BURNT,0),18) || RPAD(nvl(PFIR_VOLUME_TREES_BURNT,0),18) || RPAD(nvl(PFIR_YDIV_DIVISION_CODE,' '),8) || RPAD(nvl(PFIR_YRAN_RANGE_CODE,' '),8) outstring FROM FPM_FIRE;
CURSOR cur_FPM_JFM_MASTER IS SELECT RPAD(nvl(PJFM_BSCM_SCHEME_CODE,' '),8) || RPAD(nvl(PJFM_JFM_ID,0),13) || RPAD(nvl(PJFM_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PJFM_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(NVL(TO_CHAR(PJFM_LAUNCH_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PJFM_LOCATION,' '),20) || RPAD(nvl(PJFM_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_JFM_MASTER;
CURSOR cur_FPM_JFM_DETAILS IS SELECT RPAD(NVL(TO_CHAR(PJFD_DATE,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PJFD_EXPENDITURE,0),18) || RPAD(nvl(PJFD_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PJFD_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PJFD_NO_OF_FPS,0),13) || RPAD(nvl(PJFD_OTHER_AREA_INCLUDED,0),18) || RPAD(nvl(PJFD_OVERALL_AREA_REGENERATED,0),18) || RPAD(nvl(PJFD_PF_AREA_INCLUDED,0),18) || RPAD(nvl(PJFD_PJFM_JFM_ID,0),13) || RPAD(nvl(PJFD_RF_AREA_INCLUDED,0),18) || RPAD(nvl(PJFD_VALUE_BENEFIT_CASH,0),18) || RPAD(nvl(PJFD_VALUE_BENEFIT_GOODS,0),18) outstring FROM FPM_JFM_DETAILS;
CURSOR cur_FPM_PROTECTION_FIRE_MASTER IS SELECT RPAD(nvl(PPFM_AREA_ATTEM_TO_BE_PROT,0),18) || RPAD(nvl(PPFM_FINANCIAL_YEAR,' '),9) || RPAD(nvl(PPFM_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PPFM_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PPFM_YDIV_DIVISION_CODE,' '),8) outstring FROM FPM_PROTECTION_FIRE_MASTER;
CURSOR cur_FPM_PROTECTION_FIRE_DET IS SELECT RPAD(nvl(PPFD_AREA_ACTUALLY_PROTECTED,0),18) || RPAD(nvl(PPFD_COST,0),18) || RPAD(nvl(PPFD_FAILURE,0),18) || RPAD(nvl(PPFD_LASTUPDATE_BY,' '),30) || RPAD(NVL(TO_CHAR(PPFD_LASTUPDATE_ON,'DD-MON-RRRR'),' '),15) || RPAD(nvl(PPFD_PPFM_FINANCIAL_YEAR,' '),9) || RPAD(nvl(PPFD_PPFM_YDIV_DIVISIN_CODE,' '),8) outstring FROM FPM_PROTECTION_FIRE_DETAILS;
BEGIN
lc_error := 'begin';
lc_error := p_file_location || p_file_name ;
lh_filename := UTL_FILE.FOPEN(p_file_location, p_file_name, 'w',32767);
lc_error := 'filename';
SELECT COUNT(*) INTO ln_count FROM FPM_DAMAGE_COMPENSATION;
lc_error := 'line 1';
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10) || 'FPM_DAMAGE_COMPENSATION');
lc_error := 'line2';
FOR i IN cur_FPM_DAMAGE_COMPENSATION LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM fpm.FPM_DAMAGE_COMPENSATION_R;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
FOR i IN cur_FPM_DAMAGE_COMPENSATION_R LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM FPM_FIRE;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10)||'FPM_FIRE');
FOR i IN cur_FPM_FIRE LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM FPM_JFM_MASTER;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
FOR i IN cur_FPM_JFM_MASTER LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM FPM_JFM_DETAILS;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
FOR i IN cur_FPM_JFM_DETAILS LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM FPM_PROTECTION_FIRE_MASTER;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
FOR i IN cur_FPM_PROTECTION_FIRE_MASTER LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM FPM_PROTECTION_FIRE_DETAILS;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
FOR i IN cur_FPM_PROTECTION_FIRE_DET LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM FPM_ENCROACHMENT;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
FOR i IN cur_FPM_ENCROACHMENT LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
SELECT COUNT(*) INTO ln_count FROM FPM_ENCROACHMENT_REMOVALS;
UTL_FILE.PUT_LINE(lh_filename, RPAD(ln_count,10));
FOR i IN cur_FPM_ENCROACHMENT_REMOVALS LOOP
UTL_FILE.PUT_LINE(lh_filename, i.outstring);
END LOOP;
UTL_FILE.FCLOSE_ALL;
po_status := 'NO ERROR';
EXCEPTION
WHEN UTL_FILE.INVALID_PATH OR UTL_FILE.INVALID_MODE THEN
po_status := 'I 1';
WHEN UTL_FILE.INVALID_FILEHANDLE OR UTL_FILE.INVALID_OPERATION OR UTL_FILE.INTERNAL_ERROR OR UTL_FILE.WRITE_ERROR THEN
po_status := 'I 2';
WHEN OTHERS THEN
po_status := lc_error;
LC_ERROR:='I 4';
dbms_output.put_line(LC_ERROR);
END;
END;
If i uncomment UTL_FIle.Fopen statement, the error text will be the path name and file name.
Can anyone advise as to what should be done to resolve this on XE. It worked fine on 8i.
I have runcatproc.sql and utlfile.sql also
regards
kunalHi
On 8i you would have set the UTL_DIR_PATH parameter
in the init.ora file. Did you do this for your XE
database? I hope you are referring to the UTL_FILE_DIR parameter. I have set this parameter to value *.
Although the better approach would be to
create a directory object for the file path, an
option which was introduced in 9i..
Can you please elaborate me on this. I tried declaring the create directory statement in the package, but that didnt help. I have already created one through sql command line. How can i use this directory as an alternative to utl_file -
Hi,
Can someone please tell me what is the max. number of characters that can be written using UTL_FILE in Oracle 8.1.7?Perhaps I should have been more specific; I wanted to know how many characters can PUT_LINE or PUT function take at one time to write. Well, in 8.1.7, it is only 1000 characters on UNIX platform. Though it is not mentioned anywhere so I am not sure if this is OS limitation. However I had to do a lot of trial and error before e finding this out. Hope this would help people on the forum.
Thanks guys for your help. I know I can always count on you all.
Here is the sample code. In this, although, I had defined a buffer of 4000, but it consistently gave me 'WRITE_ERROR' for PUT_LINE or PUT function, until I reduced the buffer size used with these functions to 1000. Alternatively now I will use PUT function recursively and add NEW_LINE character after the entire buffer is read.
declare
vstr varchar(4000);
file_handle UTL_FILE.FILE_TYPE;
begin
select rpad('Testiing',990,'xyz') into vstr from dual;
file_handle := UTL_FILE.FOPEN ('/usr/users/cornwas/workplace', 'a.txt', 'w');
for i in 1..20 loop
UTL_FILE.PUT_LINE(file_handle, vstr);
UTL_FILE.FFLUSH(file_handle);
end loop;
UTL_FILE.FCLOSE(file_handle);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20100,'Invalid Path');
WHEN UTL_FILE.INVALID_MODE THEN
RAISE_APPLICATION_ERROR(-20101,'Invalid Mode');
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
RAISE_APPLICATION_ERROR(-20102,'Invalid Filehandle');
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20103,'Invalid Operation -- May signal a file locked by the OS');
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR(-20104,'Read Error');
WHEN UTL_FILE.WRITE_ERROR THEN
RAISE_APPLICATION_ERROR(-20105,'Write Error');
WHEN UTL_FILE.INTERNAL_ERROR THEN
RAISE_APPLICATION_ERROR(-20106,'Internal Error');
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20107,'No Data Found');
WHEN VALUE_ERROR THEN
RAISE_APPLICATION_ERROR(-20108,'Value Error');
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20109,'Unknown UTL_FILE Error');
end; -
UTL_FILE reqeust taking too much time for completion
Hi,
We are running utl_file reqeust.
the select statement fetching 6000 records, for this it taking 22 mins for completion.
the code is
CREATE OR REPLACE PACKAGE BODY "XXC"."XXC_MOD_IN_068_AP_TO_FIS_PKG"
AS
* Module Type : PL/SQL
* Module Name : XXC_MOD_IN_068_AP_FIS_PKG
* Description : This package is used for AP to Fiscal Interface.
* Run Env. : SQL*Plus
* Procedure Name Description
* XXC_MOD_068_AP_PR XXC_MOD_068_AP_PR Procedure is used to insert transactions
* into CSV OutPut File from Oracle Account Payables.
* Calling Module: None
* Modules Called: XXC_COMMON_INT_PK.INSERT_AUDIT
* Module Number : MOD_IN_068
* Known Bugs and Restrictions: none
* History
* =======
* Version Name Date Description of Change
* 0.1 Sanjeev Khurana 25-JULY-2011 Initial Creation.
* 0.2 Rohit 09-DEC-2011 Updated header details for the file
* 0.3 Amit Kulwal 28-AUG-2012 Updated the cursor query for incident 671520
* 0.4 Swaraj Goud 20-Nov-2012 Updated as per the CR 671520
| PACKAGE BODY
-- Actual Code Start Here
-- Procedure : XXC_MOD_068_AP_PR
-- Description : XXC_MOD_068_AP_PR Procedure is used to insert transactions
-- into CSV OUTPUT File from Oracle Account Payables.
-- Parameters:
-- Parm Name I/O Description
-- p_errbuf OUT Error message.
-- p_retcode OUT Error code. Returns 0 if no errors otherwise returns 1.
-- p_start_date IN Start Date
-- p_end_date IN End Date
PROCEDURE xxc_mod_068_ap_pr (
p_errbuf OUT VARCHAR2,
p_retcode OUT NUMBER,
p_start_date IN VARCHAR2,
p_end_date IN VARCHAR2
IS
-- Define variables and assign default values
l_sucess_count NUMBER := 0;
l_error_count NUMBER := 0;
-- Standard declaration
l_source VARCHAR2 (10);
l_target VARCHAR2 (10);
lc_module_description VARCHAR2 (50)
:= 'MOD_IN_068 - AP to Fiscal';
l_status CONSTANT VARCHAR2 (50) := 'NEW';
p_status NUMBER;
l_batch_id NUMBER;
l_batch_id_next NUMBER
:= apps_common_out_batch_id_s1.NEXTVAL;
l_proc_name VARCHAR2 (100) := 'XXC_MOD_IN_068';
l_request_id NUMBER
:= fnd_global.conc_request_id;
l_audit_master_id NUMBER := NULL;
l_mod_code VARCHAR2 (100);
l_log_type NUMBER := 1; --INFORMATION
l_det_status_success NUMBER := 0; --SUCCESS
l_det_status_inprocess NUMBER := 3; --INPROCESS
l_det_status_rejected NUMBER := 4; --REJECTED
l_det_status_err NUMBER := 3; --Error
l_det_status_complete NUMBER := 9; --COMPLETE
-- Standard who Columns
l_created_by NUMBER := fnd_global.user_id;
l_creation_date DATE := SYSDATE;
l_last_update_date DATE := SYSDATE;
l_last_update_login NUMBER := fnd_global.user_id;
v_file UTL_FILE.file_type;
l_location VARCHAR2 (150);
l_archive_location VARCHAR2 (150);
l_date VARCHAR2 (50);
l_filename VARCHAR2 (50);
l_open_mode VARCHAR2 (1) := 'W';
--- l_max_linesize NUMBER := 32767;
l_max_linesize VARCHAR2 (150); -- Updated 09-Nov-2012
--Cursor is used to fetch valid records for the interface
CURSOR get_ap_data_inv
IS
SELECT asp.segment1 supplier_ref,
-- asp.vendor_name supplier_name,
replace(asp.vendor_name, ',', ' ') supplier_name,
--aia.invoice_num invoice_number,
replace(aia.invoice_num, ',','') invoice_number,
aia.invoice_date,
aia.invoice_amount amount,
aia.doc_sequence_value unique_id,
aia.creation_date date_invoice_entered,
apsa.due_date date_invoice_paid,
aia.SOURCE user_id,
aia.payment_status_flag,
aia.invoice_type_lookup_code doc_type,
--aia.description,
replace(aia.description, ',' , ' ') description,
apsa.gross_amount
FROM ap_invoices_all aia,
ap_suppliers asp,
apps.ap_payment_schedules_all apsa
-- apps.iby_payments_all iba,
-- apps.iby_docs_payable_all dp
WHERE aia.invoice_id = apsa.invoice_id
AND aia.vendor_id = asp.vendor_id
AND aia.org_id = apsa.org_id
-- AND apsa.payment_status_flag != 'Y' -- commented for CR
-- AND dp.payment_id = iba.payment_id(+)
-- AND aia.invoice_id = dp.calling_app_doc_unique_ref2(+)
-- AND apsa.due_date <= (SYSDATE + 1)
AND TRUNC (aia.creation_date)
BETWEEN NVL (fnd_date.canonical_to_date (p_start_date),
TRUNC (aia.creation_date))
AND NVL (fnd_date.canonical_to_date (p_end_date),
TRUNC (aia.creation_date));
TYPE xxc_tbl IS TABLE OF get_ap_data_inv%ROWTYPE;
xxc_tbl1 xxc_tbl;
BEGIN
l_batch_id := apps_common_out_batch_id_s1.CURRVAL;
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_inprocess,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Process Starts',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
-- Get Module Code
BEGIN
SELECT TRIM (fval.flex_value),
TRIM (SUBSTR (fval.description,
1,
INSTR (fval.description, ' -')
INTO l_source,
l_mod_code
FROM fnd_flex_values_vl fval, fnd_flex_value_sets vset
WHERE vset.flex_value_set_id = fval.flex_value_set_id
AND vset.flex_value_set_name IN ('XXC_COMM_INT_CONFIG')
AND fval.enabled_flag = 'Y'
AND fval.description = lc_module_description;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_err,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Error Mode Code',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
raise_application_error (-20045, SQLERRM);
END;
--File Location Path for OutPut File
BEGIN
SELECT fnd_profile.VALUE ('XXC_MOD_IN_068_AP_OUTBOUND'),
fnd_profile.VALUE ('XXC_MOD_IN_068_AP_ARCHIVE')
INTO l_location,
l_archive_location
FROM DUAL;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_rejected,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Profile Value not found',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
BEGIN
SELECT TO_CHAR (SYSDATE, 'YYYYMMDDhh24miss')
INTO l_date
FROM DUAL;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_rejected,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'status not found',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
l_filename := 'AP_Fiscal_' || l_date || '.csv';
v_file :=
UTL_FILE.fopen (LOCATION => l_location,
filename => l_filename,
open_mode => l_open_mode,
max_linesize => l_max_linesize
-- Changed as per Sarah's email on 9th Decemeber
/* UTL_FILE.put_line (v_file,
'SUPPLIER_REF'
|| ','
|| 'SUPPLIER_NAME'
|| ','
|| 'INVOICE_NUMBER'
|| ','
|| 'INVOICE_DATE'
|| ','
|| 'AMOUNT'
|| ','
|| 'UNIQUE_ID'
|| ','
|| 'DATE_INVOICE_ENTERED'
|| ','
|| 'DATE_INVOICE_PAID'
|| ','
|| 'USER_ID'
|| ','
|| 'PAYMENT_STATUS_FLAG'
|| ','
|| 'DOC_TYPE'
|| ','
|| 'DESCRIPTION'
|| ','
|| 'PAYMENT_AMOUNT'
UTL_FILE.put_line (v_file,
'SUPPLIERREF'
|| ','
|| 'SUPPLIERNAME'
|| ','
|| 'INVOICENUMBER'
|| ','
|| 'DATE'
|| ','
|| 'AMOUNT'
|| ','
|| 'UNIQUEID'
|| ','
|| 'DATEINVOICEENTERED'
|| ','
|| 'DATEINVOICEPAID'
|| ','
|| 'USERID'
|| ','
|| 'PAYMENTSTATUS'
|| ','
|| 'DOCTYPE'
|| ','
|| 'DESCRIPTION'
|| ','
|| 'PAYMENTAMOUNT');
UTL_FILE.put_line (v_file,
'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX');
open get_ap_data_inv;
loop
fetch get_ap_data_inv bulk collect into xxc_tbl1 limit 6000;
fnd_file.put_line(fnd_file.log, 'Cursor Count is : '||xxc_tbl1.count);
for i in xxc_tbl1.first .. xxc_tbl1.count
--FOR cur_rec IN get_ap_data_inv
LOOP
BEGIN
--Common package used for proper sequence for Record_id and Bath_id
l_sucess_count := l_sucess_count + 1;
--Insert into CSV file
fnd_file.put_line (fnd_file.LOG, 'Before Utl file');
UTL_FILE.put_line (v_file,
xxc_tbl1(i).supplier_ref
|| ','
|| xxc_tbl1(i).supplier_name
|| ','
|| xxc_tbl1(i).invoice_number
|| ','
|| xxc_tbl1(i).invoice_date
|| ','
|| xxc_tbl1(i).amount
|| ','
|| xxc_tbl1(i).unique_id
|| ','
|| xxc_tbl1(i).date_invoice_entered
|| ','
|| xxc_tbl1(i).date_invoice_paid
|| ','
|| xxc_tbl1(i).user_id
|| ','
|| xxc_tbl1(i).payment_status_flag
|| ','
|| xxc_tbl1(i).doc_type
|| ','
|| xxc_tbl1(i).description
|| ','
|| xxc_tbl1(i).gross_amount);
fnd_file.put_line (fnd_file.LOG,
'Supplier Reference : ' || xxc_tbl1(i).supplier_ref);
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_complete,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Inserting records from AP to Fiscal Successfully',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
EXCEPTION
WHEN OTHERS
THEN
l_error_count := l_error_count + 1;
fnd_file.put_line (fnd_file.LOG,
'Error While Inserting from AP to Fiscal '
|| SQLERRM);
-- Create audit log for AP Inv records insert Exception
--Insert into the Audit table XXC_COMM_AUDIT_DETAIL_LOG and XXC_COMM_AUDIT_MASTER_LOG
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_rejected,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Error While Inserting from AP to Fiscal',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
END LOOP;
exit when get_ap_data_inv%NOTFOUND;
end loop;
close get_ap_data_inv;
UTL_FILE.fclose (v_file);
UTL_FILE.fcopy (l_location,
l_filename,
l_archive_location,
l_filename
-- Create audit log for Successfully processed records
-- Procedure call to insert in Audit tables
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_complete,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Compeleted Sucessfully AP to Fiscal',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
--Insert into the Audit table XXC_COMM_AUDIT_DETAIL_LOG and XXC_COMM_AUDIT_MASTER_LOG for populating email drop table
BEGIN
SELECT transaction_status
INTO p_status
FROM xxc_comm_audit_master_log
WHERE audit_master_id = l_audit_master_id;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_err,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Status Error',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
IF p_status <> 0
THEN
xxc_comm_audit_log_pk.populate_email_drop_table (l_audit_master_id,
l_batch_id);
END IF;
EXCEPTION
WHEN UTL_FILE.invalid_path
THEN
UTL_FILE.fclose (v_file);
raise_application_error (-20000, 'File location is invalid.');
WHEN UTL_FILE.invalid_mode
THEN
UTL_FILE.fclose (v_file);
raise_application_error (-20001,
'The open_mode parameter in FOPEN is invalid.');
WHEN UTL_FILE.invalid_filehandle
THEN
UTL_FILE.fclose (v_file);
raise_application_error (-20002, 'File handle is invalid.');
WHEN UTL_FILE.invalid_operation
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20003,
'File could not be opened or operated on as requested.');
WHEN UTL_FILE.write_error
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20005,
'Operating system error occurred during the write operation.');
WHEN UTL_FILE.file_open
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20008,
'The requested operation failed because the file is open.');
WHEN UTL_FILE.invalid_maxlinesize
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20009,
'The MAX_LINESIZE value for FOPEN() is invalid; it should '
|| 'be within the range 1 to 32767.');
COMMIT;
ROLLBACK TO data_extract;
WHEN OTHERS
THEN
raise_application_error (-20045, SQLERRM);
UTL_FILE.fclose (v_file);
END xxc_mod_068_ap_pr;
END xxc_mod_in_068_ap_to_fis_pkg;
Show Errors
Iam implemented BULK collect concept in programe,can anyone please suggest how can I imporve performance....
Thanks,
RakeshCREATE OR REPLACE PACKAGE BODY "XXC"."XXC_MOD_IN_068_AP_TO_FIS_PKG"
AS
PROCEDURE xxc_mod_068_ap_pr (
p_errbuf OUT VARCHAR2,
p_retcode OUT NUMBER,
p_start_date IN VARCHAR2,
p_end_date IN VARCHAR2
IS
-- Define variables and assign default values
l_sucess_count NUMBER := 0;
l_error_count NUMBER := 0;
-- Standard declaration
l_source VARCHAR2 (10);
l_target VARCHAR2 (10);
lc_module_description VARCHAR2 (50)
:= 'MOD_IN_068 - AP to Fiscal';
l_status CONSTANT VARCHAR2 (50) := 'NEW';
p_status NUMBER;
l_batch_id NUMBER;
l_batch_id_next NUMBER
:= apps_common_out_batch_id_s1.NEXTVAL;
l_proc_name VARCHAR2 (100) := 'XXC_MOD_IN_068';
l_request_id NUMBER
:= fnd_global.conc_request_id;
l_audit_master_id NUMBER := NULL;
l_mod_code VARCHAR2 (100);
l_log_type NUMBER := 1; --INFORMATION
l_det_status_success NUMBER := 0; --SUCCESS
l_det_status_inprocess NUMBER := 3; --INPROCESS
l_det_status_rejected NUMBER := 4; --REJECTED
l_det_status_err NUMBER := 3; --Error
l_det_status_complete NUMBER := 9; --COMPLETE
-- Standard who Columns
l_created_by NUMBER := fnd_global.user_id;
l_creation_date DATE := SYSDATE;
l_last_update_date DATE := SYSDATE;
l_last_update_login NUMBER := fnd_global.user_id;
v_file UTL_FILE.file_type;
l_location VARCHAR2 (150);
l_archive_location VARCHAR2 (150);
l_date VARCHAR2 (50);
l_filename VARCHAR2 (50);
l_open_mode VARCHAR2 (1) := 'W';
--- l_max_linesize NUMBER := 32767;
l_max_linesize VARCHAR2 (150); -- Updated 09-Nov-2012
--Cursor is used to fetch valid records for the interface
CURSOR get_ap_data_inv
IS
SELECT asp.segment1 supplier_ref,
-- asp.vendor_name supplier_name,
replace(asp.vendor_name, ',', ' ') supplier_name,
--aia.invoice_num invoice_number,
replace(aia.invoice_num, ',','') invoice_number,
aia.invoice_date,
aia.invoice_amount amount,
aia.doc_sequence_value unique_id,
aia.creation_date date_invoice_entered,
apsa.due_date date_invoice_paid,
aia.SOURCE user_id,
aia.payment_status_flag,
aia.invoice_type_lookup_code doc_type,
--aia.description,
replace(aia.description, ',' , ' ') description,
apsa.gross_amount
FROM ap_invoices_all aia,
ap_suppliers asp,
apps.ap_payment_schedules_all apsa
-- apps.iby_payments_all iba,
-- apps.iby_docs_payable_all dp
WHERE aia.invoice_id = apsa.invoice_id
AND aia.vendor_id = asp.vendor_id
AND aia.org_id = apsa.org_id
-- AND apsa.payment_status_flag != 'Y' -- commented for CR
-- AND dp.payment_id = iba.payment_id(+)
-- AND aia.invoice_id = dp.calling_app_doc_unique_ref2(+)
-- AND apsa.due_date <= (SYSDATE + 1)
AND TRUNC (aia.creation_date)
BETWEEN NVL (fnd_date.canonical_to_date (p_start_date),
TRUNC (aia.creation_date))
AND NVL (fnd_date.canonical_to_date (p_end_date),
TRUNC (aia.creation_date));
TYPE xxc_tbl IS TABLE OF get_ap_data_inv%ROWTYPE;
xxc_tbl1 xxc_tbl;
BEGIN
l_batch_id := apps_common_out_batch_id_s1.CURRVAL;
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_inprocess,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Process Starts',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
-- Get Module Code
BEGIN
SELECT TRIM (fval.flex_value),
TRIM (SUBSTR (fval.description,
1,
INSTR (fval.description, ' -')
INTO l_source,
l_mod_code
FROM fnd_flex_values_vl fval, fnd_flex_value_sets vset
WHERE vset.flex_value_set_id = fval.flex_value_set_id
AND vset.flex_value_set_name IN ('XXC_COMM_INT_CONFIG')
AND fval.enabled_flag = 'Y'
AND fval.description = lc_module_description;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_err,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Error Mode Code',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
raise_application_error (-20045, SQLERRM);
END;
--File Location Path for OutPut File
BEGIN
SELECT fnd_profile.VALUE ('XXC_MOD_IN_068_AP_OUTBOUND'),
fnd_profile.VALUE ('XXC_MOD_IN_068_AP_ARCHIVE')
INTO l_location,
l_archive_location
FROM DUAL;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_rejected,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Profile Value not found',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
BEGIN
SELECT TO_CHAR (SYSDATE, 'YYYYMMDDhh24miss')
INTO l_date
FROM DUAL;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_rejected,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'status not found',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
l_filename := 'AP_Fiscal_' || l_date || '.csv';
v_file :=
UTL_FILE.fopen (LOCATION => l_location,
filename => l_filename,
open_mode => l_open_mode,
max_linesize => l_max_linesize
-- Changed as per Sarah's email on 9th Decemeber
/* UTL_FILE.put_line (v_file,
'SUPPLIER_REF'
|| ','
|| 'SUPPLIER_NAME'
|| ','
|| 'INVOICE_NUMBER'
|| ','
|| 'INVOICE_DATE'
|| ','
|| 'AMOUNT'
|| ','
|| 'UNIQUE_ID'
|| ','
|| 'DATE_INVOICE_ENTERED'
|| ','
|| 'DATE_INVOICE_PAID'
|| ','
|| 'USER_ID'
|| ','
|| 'PAYMENT_STATUS_FLAG'
|| ','
|| 'DOC_TYPE'
|| ','
|| 'DESCRIPTION'
|| ','
|| 'PAYMENT_AMOUNT'
UTL_FILE.put_line (v_file,
'SUPPLIERREF'
|| ','
|| 'SUPPLIERNAME'
|| ','
|| 'INVOICENUMBER'
|| ','
|| 'DATE'
|| ','
|| 'AMOUNT'
|| ','
|| 'UNIQUEID'
|| ','
|| 'DATEINVOICEENTERED'
|| ','
|| 'DATEINVOICEPAID'
|| ','
|| 'USERID'
|| ','
|| 'PAYMENTSTATUS'
|| ','
|| 'DOCTYPE'
|| ','
|| 'DESCRIPTION'
|| ','
|| 'PAYMENTAMOUNT');
UTL_FILE.put_line (v_file,
'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX'
|| ','
|| 'XX');
open get_ap_data_inv;
loop
fetch get_ap_data_inv bulk collect into xxc_tbl1 limit 6000;
fnd_file.put_line(fnd_file.log, 'Cursor Count is : '||xxc_tbl1.count);
for i in xxc_tbl1.first .. xxc_tbl1.count
--FOR cur_rec IN get_ap_data_inv
LOOP
BEGIN
--Common package used for proper sequence for Record_id and Bath_id
l_sucess_count := l_sucess_count + 1;
--Insert into CSV file
fnd_file.put_line (fnd_file.LOG, 'Before Utl file');
UTL_FILE.put_line (v_file,
xxc_tbl1(i).supplier_ref
|| ','
|| xxc_tbl1(i).supplier_name
|| ','
|| xxc_tbl1(i).invoice_number
|| ','
|| xxc_tbl1(i).invoice_date
|| ','
|| xxc_tbl1(i).amount
|| ','
|| xxc_tbl1(i).unique_id
|| ','
|| xxc_tbl1(i).date_invoice_entered
|| ','
|| xxc_tbl1(i).date_invoice_paid
|| ','
|| xxc_tbl1(i).user_id
|| ','
|| xxc_tbl1(i).payment_status_flag
|| ','
|| xxc_tbl1(i).doc_type
|| ','
|| xxc_tbl1(i).description
|| ','
|| xxc_tbl1(i).gross_amount);
fnd_file.put_line (fnd_file.LOG,
'Supplier Reference : ' || xxc_tbl1(i).supplier_ref);
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_complete,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Inserting records from AP to Fiscal Successfully',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
EXCEPTION
WHEN OTHERS
THEN
l_error_count := l_error_count + 1;
fnd_file.put_line (fnd_file.LOG,
'Error While Inserting from AP to Fiscal '
|| SQLERRM);
-- Create audit log for AP Inv records insert Exception
--Insert into the Audit table XXC_COMM_AUDIT_DETAIL_LOG and XXC_COMM_AUDIT_MASTER_LOG
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_rejected,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Error While Inserting from AP to Fiscal',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
END LOOP;
exit when get_ap_data_inv%NOTFOUND;
end loop;
close get_ap_data_inv;
UTL_FILE.fclose (v_file);
UTL_FILE.fcopy (l_location,
l_filename,
l_archive_location,
l_filename
-- Create audit log for Successfully processed records
-- Procedure call to insert in Audit tables
xxc_common_int_pk.insert_audit
(p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_complete,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Compeleted Sucessfully AP to Fiscal',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
--Insert into the Audit table XXC_COMM_AUDIT_DETAIL_LOG and XXC_COMM_AUDIT_MASTER_LOG for populating email drop table
BEGIN
SELECT transaction_status
INTO p_status
FROM xxc_comm_audit_master_log
WHERE audit_master_id = l_audit_master_id;
EXCEPTION
WHEN OTHERS
THEN
xxc_common_int_pk.insert_audit (p_batch_id => l_batch_id,
p_request_id => l_request_id,
p_source_system => l_source,
p_proc_name => l_proc_name,
p_log_type => l_log_type,
p_det_status => l_det_status_err,
p_msg_code => NULL,
p_entity => NULL,
p_msg_desc => 'Status Error',
p_mast_request_id => l_request_id,
p_record_id => NULL,
p_source => l_source,
p_target => l_target,
p_email => NULL,
p_mod_code => l_mod_code,
p_audit_master_id => l_audit_master_id
END;
IF p_status <> 0
THEN
xxc_comm_audit_log_pk.populate_email_drop_table (l_audit_master_id,
l_batch_id);
END IF;
EXCEPTION
WHEN UTL_FILE.invalid_path
THEN
UTL_FILE.fclose (v_file);
raise_application_error (-20000, 'File location is invalid.');
WHEN UTL_FILE.invalid_mode
THEN
UTL_FILE.fclose (v_file);
raise_application_error (-20001,
'The open_mode parameter in FOPEN is invalid.');
WHEN UTL_FILE.invalid_filehandle
THEN
UTL_FILE.fclose (v_file);
raise_application_error (-20002, 'File handle is invalid.');
WHEN UTL_FILE.invalid_operation
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20003,
'File could not be opened or operated on as requested.');
WHEN UTL_FILE.write_error
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20005,
'Operating system error occurred during the write operation.');
WHEN UTL_FILE.file_open
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20008,
'The requested operation failed because the file is open.');
WHEN UTL_FILE.invalid_maxlinesize
THEN
UTL_FILE.fclose (v_file);
raise_application_error
(-20009,
'The MAX_LINESIZE value for FOPEN() is invalid; it should '
|| 'be within the range 1 to 32767.');
COMMIT;
ROLLBACK TO data_extract;
WHEN OTHERS
THEN
raise_application_error (-20045, SQLERRM);
UTL_FILE.fclose (v_file);
END xxc_mod_068_ap_pr;
END xxc_mod_in_068_ap_to_fis_pkg;Please verify... -
Samples using UTL_FILE package
hello;
I would like to use the utl_file package: fopen, put_line ...
can you send me some samples using this package.
thanks to your help
mam
nulldeclare
T1 UTL_FILE.FILE_TYPE;
begin
begin
T1:= UTL_FILE.FOPEN
('/u02/applmgr/10.7p161/eye/3.3.1/out','filename.dat','w');
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('Invalid Path');
WHEN UTL_FILE.INVALID_MODE THEN
DBMS_OUTPUT.PUT_LINE('Invalid Mode');
WHEN UTL_FILE.INVALID_OPERATION THEN
DBMS_OUTPUT.PUT_LINE('Invalid Operation');
end;
UTL_FILE.PUT(T1,'PROD DATE ');
UTL_FILE.PUT(T1,'PRODUCT ');
UTL_FILE.PUT_LINE(T1,'INTEREST TYPE ');
UTL_FILE.PUT(T1,'LEASE NUMBER ');
begin
UTL_FILE.FCLOSE(T1);
EXCEPTION
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('write error');
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
DBMS_OUTPUT.PUT_LINE('Invald File Handle');
end;
END;
mamoudou (guest) wrote:
: hello;
: I would like to use the utl_file package: fopen, put_line ...
: can you send me some samples using this package.
: thanks to your help
: mam
null -
Utl_file raise INVALID_WRITE_ERROR
Hi all,
I try to use utl_file package provided by Oracle 8.1.5 to write a text file in XML format. Oracle runs in UNIX environment.
I use the following command to open a new file:
UTL_FILE.FOPEN(P_PATH,P_FILENAME,'w',32767);
I use the put_line to write a line, such as
UTL_FILE.PUT_LINE(P_FILEHANDLE,' <Font x:Family="Swiss" ss:Bold="1"/>');
The problem is that utl_file always raises UTL_FILE.WRITE_ERROR after writting 234 lines and 8192 characters . Is there potential limition set by Oracle or Unix for the size of the written file?
ThanksHi,
Sorry, I don't have access to Oracle 8 documentation. The following is based on Oracle 11, but I'd be surprised if it was different for earlier versions.
There's no limit to the size of the file.
There is a limit to the size of a line, which you're already setting by passing the fourth argument (32767) to fopen. That means you can't write more than 32767 characters in a single call to put_line, or in consecutive calls to put.
I don't see any obvious mistakes in what you posted.
Post a complete program that gets the same error. -
I have written a following procedure and it complies successfully.
create or replace procedure utl_file_test_write (
path in varchar2,
filename in varchar2,
firstline in varchar2,
secondline in varchar2)
is
output_file utl_file.file_type;
begin
output_file := utl_file.fopen (path,filename, 'W');
utl_file.put_line (output_file, firstline);
utl_file.put_line (output_file, secondline);
utl_file.fclose(output_file);
end;
I have create the directory using the following command
SQL> CREATE DIRECTORY log_dir AS 'd:\oracle\oraclelog_dir';
Directory created
SQL> GRANT READ ON DIRECTORY log_dir TO DBA;
Grant succeeded
SQL> CREATE DIRECTORY out_dir AS 'd:\oracle\oracleout_dir';
Directory created
SQL> GRANT READ ON DIRECTORY out_dir TO DBA;
Grant succeeded
SQL> COMMIT;
But when I execute this then it gives the following error.
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "SYS.UTL_FILE", line 98
ORA-06512: at "SYS.UTL_FILE", line 157
ORA-06512: at "UTL_FILE_TEST_WRITE", line 9
ORA-06512: at line 1
I am using the following version.
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
PL/SQL Release 8.1.5.0.0 - Production
CORE Version 8.1.3.0.0 - Production
TNS for Solaris: Version 8.1.5.0.0 - Production
NLSRTL Version 3.4.0.0.0 - Production
Can anybody help me how can I solve the problem.
Thanks in advanceI think you are not handeling the exceptions. First you add the exceptions and it will tell you what kind of exception is raised.
Try:
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20100,'Invalid Path');
WHEN utl_file.invalid_mode THEN
raise_application_error(-20101,'Invalid Mode');
WHEN utl_file.invalid_operation THEN
raise_application_error(-20102,'Invalid Operation');
WHEN utl_file.invalid_filehandle THEN
raise_application_error(-20103,'Invalid Filehandle');
WHEN utl_file.write_error THEN
raise_application_error(-20104, 'Write Error');
WHEN utl_file.read_error THEN
raise_application_error(-20105,'Read Error');
WHEN utl_file.internal_error THEN
raise_application_error(-20106,'Internal Error');
WHEN others THEN
utl_file.fclose(v_file_id);
raise_application_error (-20007, sqlerrm);HTH
Ghulam -
UTL_FILE help/samples
Hello Folks,
I need to write a routine to read in a CSV file parse it and inser the data into a table.
Does anybody have examples?
TIAUse this as a skeleton:
set serveroutput on size 1000000 format word_wrapped
set verify off
DECLARE
EOF CONSTANT VARCHAR2(30) := '~~+~~+~~';
iCount NUMBER;
sEOF VARCHAR2(30);
sPath VARCHAR2(2000);
sRecord VARCHAR2(2000);
sSQLCode NUMBER;
sSQLErrM VARCHAR2(255);
pFileHandle utl_file.file_type;
BEGIN
dbms_output.enable(1000000);
iCount := 0;
sEOF := '';
sPath := 'C:\Data';
pFileHandle := utl_file.fopen(sPath, 'file.cvs', 'r');
loop
BEGIN
utl_file.get_line(pFileHandle, sRecord);
EXCEPTION
when NO_DATA_FOUND then sEOF := EOF;
END;
exit when sEOF = EOF;
iCount := iCount + 1;
dbms_output.put_line(sRecord);
end loop;
commit;
dbms_output.put_line("Records read: "| |iCount);
utl_file.fclose(pFileHandle);
EXCEPTION
when UTL_FILE.INVALID_OPERATION then
utl_file.fclose(pFileHandle);
raise_application_error(-20001, 'Invalid Operation');
when UTL_FILE.INVALID_FILEHANDLE then
utl_file.fclose(pFileHandle);
raise_application_error(-20002, 'Invalid File Handle');
when UTL_FILE.WRITE_ERROR then
utl_file.fclose(pFileHandle);
raise_application_error(-20003, 'Write Error');
when UTL_FILE.INTERNAL_ERROR then
utl_file.fclose(pFileHandle);
raise_application_error(-20004, 'Internal Error');
when UTL_FILE.INVALID_PATH then
utl_file.fclose(pFileHandle);
raise_application_error(-20005, 'Invalid Path ['| |sPath| |']');
when UTL_FILE.INVALID_MODE then
utl_file.fclose(pFileHandle);
raise_application_error(-20006, 'Invalid Mode');
when UTL_FILE.READ_ERROR then
utl_file.fclose(pFileHandle);
raise_application_error(-20007, 'Read Error');
when OTHERS then
utl_file.fclose(pFileHandle);
sSQLCode := SQLCODE;
sSQLErrM := substr(SQLERRM, 1, 255);
raise_application_error(-20008, sSQLCode| |' - '| |sSQLErrM);
END;
To chop the record into separate fields you must use something like:
iStart := instr(sRecord, '|', 1, 2) + 1;
iLen := instr(sRecord, '|', 1, 3) - iStart;
if iLen = 0 then
sField := '#NULL#';
else
sField := substr(sRecord, iStart, iLen);
null -
UTL_FILE in a trigger or calling a stored procedure within a trigger
Hello,
We are using Oracle 8i version where I need to either call a SP within a trigger or use UTL_FILE within a trigger.
1. SP runs fine by itself to write to a file but when I try calling SP within a trigger-> I get INVALID Path - is there some kind of restriction with DB triggers and UTL_FILE options
create or replace trigger testtrig
after insert on test_table
for each row when (new.stat_code = '99')
BEGIN
utl_file_test_write;
EXCEPTION
WHEN others THEN
raise_application_error(-20000, sqlerrm);
END;
2. use UTL_FILE with a trigger
create or replace trigger testtrig
after insert on test_table
for each row when (new.stat_code <> '99')
DECLARE
v_line varchar2(32767);
v_location varchar2(80) :='/u01/oraadmin/udump';
v_filename varchar2(80) := 'KC11.txt';
v_handle utl_file.file_type;
BEGIN
dbms_output.put_line('Location is'||v_location);
dbms_output.put_line('Location is'||v_filename);
v_filename := :new.emp_id;
v_handle := utl_file.fopen(v_location, v_filename,'W',32767);
v_line := :new.emp_id;
utl_file.put_line(v_handle,v_line);
utl_file.fclose(v_handle);
EXCEPTION
WHEN TOO_MANY_ROWS THEN
dbms_output.PUT_LINE('Too Many Rows');
WHEN NO_DATA_FOUND THEN
dbms_output.PUT_LINE('No Data Found');
--WHEN utl_file.invalid_path THEN
-- RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_path');
WHEN utl_file.invalid_mode THEN
RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_mode');
WHEN utl_file.invalid_filehandle THEN
RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_filehandle');
WHEN utl_file.invalid_operation THEN
RAISE_APPLICATION_ERROR(-20000, 'utl_file.invalid_operation');
WHEN utl_file.read_error THEN
RAISE_APPLICATION_ERROR(-20001, 'utl_file.read_error');
WHEN utl_file.write_error THEN
RAISE_APPLICATION_ERROR(-20001, 'utl_file.write_error');
WHEN utl_file.internal_error THEN
RAISE_APPLICATION_ERROR(-20001, 'utl_file.internal_error');
End;
I still get INVALID_PATH. What am I missing?
Any help is greatly appreciated.
Thanks.Hi,
from docs on UTL_FIL.FOPEN:
location:
Directory location of file. This string is a directory object name and is case sensitive. The default is uppercase. Read privileges must be granted on this directory object for the UTL_FILE user to run FOPEN.This, '/u01/oraadmin/udump' does not look like the name of a DIRECTORY object.
Besides, the whole idea of having UTL_FILE commands directly in a trigger body sucks. At the least stay with a stored procedure.
And have you considered what should happen with that file in case the transaction is rolled back?
Regards
Peter -
Max_linesize in UTL_FILE
I always get the exeption "UTL_FILE.WRITE_ERROR" when I'm trying to write
to a file and the raw gets longer than (aprox) 2030.
I've tried to open the file with specific max_linesize to eliminate the exeption:
Ex:
v_handle := Utl_File.Fopen (
location => c_location,
filename => c_filename,
open_mode => 'w',
max_linesize => v_raw_size );
This statement replies "to many arguments".
I'm aware of the fact that databse-version is old, it's 7.3.
How am I suppose to specify max_linesize in this version of database.
I believe this is the issue about the exeption.
Thanks a lot!
JohanThe parameter max_linesize does not exists in 7.3. You cannot write more than 1k (I think) per line.
Your only option is to break into more than one line, if you use UTL_FILE -
Line length in UTL_FILE
HI.. sorry for basic question but....
1- I want to create a file from database.
2- The length of lines to append to the file is 1300
3- when I try to close the file or make fflush to the file
(write lines into the file), exception utl_file.write_error
is fired.
4- when the length of the line is 750 (i,e) that's not occurs
WAY???
What is te maximun length for the line to append???
May be concern of Operating System variable??
THANK's and excuseme for my regular english.
JOHNNY1) Read about utl_file.put (tells you the line max)
2) Doc for the rest of UTL_FILE
http://technet.oracle.com/docs/products/oracle9i/doc_library/901_doc/appdev.901/a89852/utl_fi11.htm#1001590
http://technet.oracle.com/docs/products/oracle9i/doc_library/901_doc/appdev.901/a89852/utl_file.htm#1002119 -
UTL_FILE - Write to a file on a mapped network drive
Hello,
I am trying to get the UTL_FILE package to write a file to a mapped network drive on
Windows NT. We have the following definition in the init<SID>.ora file pointing to the
network drive:
UTL_FILE_DIR=v:\hawkrpt
Here is the code to write to the file:
CREATE OR REPLACE PACKAGE pkgUtlFileTest AS -- package spec
PROCEDURE isp_UtlFileTest ( vcDir IN VARCHAR2,
vcFileName IN VARCHAR2,
vcOpenType IN VARCHAR2,
vcMessage1 IN VARCHAR2 );
END pkgUtlFileTest;
CREATE OR REPLACE PACKAGE BODY pkgUtlFileTest AS -- package body
PROCEDURE isp_UtlFileTest ( vcDir IN VARCHAR2,
vcFileName IN VARCHAR2,
vcOpenType IN VARCHAR2,
vcMessage1 IN VARCHAR2 ) IS
-- vcDir is the utl file directory
-- vcOpenTpye is the open type a = append, w = write or r = read
-- vcFileName is any file name you want.
-- vcmessage is the entry you want placed into the file
vcUtlFile UTL_FILE.FILE_TYPE;
BEGIN
IF LOWER(vcOpenType) = 'a' OR LOWER(vcOpenType) = 'w' THEN
vcUtlFile := UTL_FILE.FOPEN(vcDir, vcFileName, vcOpenType);
UTL_FILE.PUT_LINE(vcUtlFile, vcMessage1);
UTL_FILE.FCLOSE(vcUtlFile);
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('no_data_found');
UTL_FILE.FCLOSE_ALL ();
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
UTL_FILE.FCLOSE_ALL ();
WHEN UTL_FILE.READ_ERROR THEN
DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
UTL_FILE.FCLOSE_ALL ();
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
UTL_FILE.FCLOSE_ALL ();
WHEN UTL_FILE.INVALID_OPERATION THEN
DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_OPERATION');
UTL_FILE.FCLOSE_ALL ();
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('OTHER ERROR' );
UTL_FILE.FCLOSE_ALL ();
END isp_UtlFileTest;
END pkgUtlFileTest;
Here is the code to execute the stored procedure:
Begin
pkgUtlFileTest.ISP_UTLFILETEST('v:\hawkrpt','test.txt','w','This is a test');
End;
When the stored procedure is executed, the following error is returned:
UTL_FILE.INVALID_OPERATION
Can someone tell me how to get the UTL_FILE package to write a file to a network drive
on a Windows NT server?
Your help will be greatly appreciated!
MikeDid you restart the database after changing the init.ora parameter? Make sure that you have this new value in v$parameter view.
-
PL/SQL package using utl_file.fopen gets invalid_path error
The init.ora file has utl_file_dir = * in it. When writing a package trying to utilize the utl_file.fopen the invalid_path error always occurs. What is the fix to resolve the path error?
create or replace package body TEST_UTL_FILE is
-- Purpose : Sample package that uses UTL_FILE procedure(s)
-- ===========================================================================================================
-- Process Request
-- ===========================================================================================================
procedure Process_Request is
-- Local Variable(s)
v_file_id sys.UTL_FILE.FILE_TYPE;
v_buffer varchar2(32767);
begin
v_file_id := sys.utl_file.FOPEN('D:\Oracle\XMLFiles',
'Sample1.xml',
'R');
sys.utl_file.GET_LINE(v_file_id, v_buffer);
return;
exception
-- Error number -29280
WHEN UTL_FILE.INVALID_PATH THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_path');
-- Error number -29281
WHEN UTL_FILE.INVALID_MODE THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_mode');
-- Error number -29282
WHEN UTL_FILE.INVALID_FILEHANDLE THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_filehandle');
-- Error number -29283
WHEN UTL_FILE.INVALID_OPERATION THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_operation');
-- Error number -29284
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR(-20001, 'read_error');
-- Error number -29285
WHEN UTL_FILE.WRITE_ERROR THEN
RAISE_APPLICATION_ERROR(-20001, 'write_error');
-- Error number -29286
WHEN UTL_FILE.INTERNAL_ERROR THEN
RAISE_APPLICATION_ERROR(-20001, 'internal_error');
-- Error number -29287
WHEN UTL_FILE.invalid_maxlinesize THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_maxlinesize');
-- Error number -29288
WHEN UTL_FILE.invalid_filename THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_filename');
-- Error number -29289
WHEN UTL_FILE.access_denied THEN
RAISE_APPLICATION_ERROR(-20001, 'access_denied');
-- Error number -29290
WHEN UTL_FILE.invalid_offset THEN
RAISE_APPLICATION_ERROR(-20001, 'invalid_offset');
-- Error number -29291
WHEN UTL_FILE.delete_failed THEN
RAISE_APPLICATION_ERROR(-20001, 'delete_failed');
-- Error number -29292
WHEN UTL_FILE.rename_failed THEN
RAISE_APPLICATION_ERROR(-20001, 'rename_failed');
-- Error number unknown
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001, 'other_error');
end Process_Request;
end TEST_UTL_FILE;
Errors:
ORA-20001: invalid_path
ORA-06512: at "SYS.TEST_UTL_FILE", line 21
ORA-06512: at line 3
Maybe you are looking for
-
New MBP and Time Machine won't let me search out my NAS to save too. Any ideas?
When trying to set up time machine and using a NAS drive in my wireless network Time Machine won't let me search and select the storage device. I can access the storage and save/retrieve files so I can see and use it. Anyone got any ideas please? Bra
-
Sales Order Acknowledgement by Workflow
Hi All, The client requirement is to send the Order acknowledgement to their customers by Workflow and not through the output condition technique. I am new to workflow. The order acknowledment needs to be sent as an attachment in the e-mail and it sh
-
Setting Acrobat Reader as default
when I open a PDF file it opens in Preview. How do I change it so that by default the Acrobat Reader opens the PDf files. I went to the Acrobat Reader website but their instructions didn't work for me. Thank you for responding.
-
Financial Reportin Studio: Top down reporting, rollup then leaf level
Hi, I am trying to build a report in Hyperion Reporting Studio. I need to build it so that it is a top down report. I am doing this for the Account dimension. For example I want the report to start with Balance Sheet ( our top rollup) then go down to
-
Unknown error (-50) after ios5 update
I just updated my iphone 3GS to ios5. It seemed to work fine. The problem is now that whenever i try to sync the iphone to get my contacts and old settings back on the phone it returns the following error message: "An error occurred while restoring t