Utl_file.fopen
Hi everyone..
I am using utl_file to write delimited data into text files.In the utl_file.fopen i changed the default l "max line size" to 32767 when i got some error regarding the line size.After changing that that max line size paramaterer,I am getting lot of space after each line.
Does that max line size parameter means that every line "should" be that size? why i am getting lot of space after each line?
question1:
======
How to remove that empty spaces that i got after each line in my text file?
FILEHANDLE := UTL_FILE.FOPEN('TEST_UTL_FILE','file_name.txt', 'W',32767);And i am trying to find the length of the string that i am passing it utl_file.put_line
I am trying to insert that length to a "test" table ,so that i can check the max length of each line that is passing to the utl_file.
I have this insert command in my PL/SQL block
insert into test_number_char (num) values (dbms_lob.getlength(EXTRACTED_STRING)); and the data type of "num" column is number(20,0)
I am getting the following error .
ERROR getting members -1461 ORA-01461: can bind a LONG value only for insert into a LONG columnquestion 2:
=======
How to get the length of the string that i am writing into file?
Thanks
phani
Hi Phani,
>
question1:
======
How to remove that empty spaces that i got after each line in my text file?
>
something like this,
string := Rtrim(string,' ');question 2:
=======
How to get the length of the string that i am writing into file?
>
look at this,
SQL> Set Serveroutput on
SQL> Create or Replace Directory SOME_DIR As 'C:\Temp';
Directory created
SQL> Create table Test_ As (Select dbms_random.string('X',10) as Txt From dual Connect by Level <= 2500);
Table created
SQL>
SQL> Declare
2 v_column Varchar2(30);
3 l_utl_dir Varchar2(30) := 'SOME_DIR';
4 l_utl_file Varchar2(30) := 'Some_File.txt';
5 l_header Varchar2(32767) := Null;
6 l_utl_id UTL_FILE.FILE_TYPE;
7 Begin
8 DBMS_OUTPUT.ENABLE(32767);
9
10 l_utl_id := UTL_FILE.FOPEN( location => l_utl_dir
11 , filename => l_utl_file
12 , open_mode => 'w'
13 , max_linesize => 32767);
14
15 For i IN (SELECT Rowid
16 FROM TEST_) Loop
17
18 For x IN (SELECT COLUMN_NAME
19 , TABLE_NAME
20 FROM ALL_TAB_COLS
21 WHERE TABLE_NAME = 'TEST_') Loop
22
23 Execute Immediate 'select ' || x.column_name || ' from ' ||
24 x.table_name || ' where rowid = :pi_input'
25 INTO v_column
26 Using IN i.Rowid;
27
28 l_header := l_header || v_column || ' ';
29
30 End Loop;
31 End Loop;
32
33 UTL_FILE.PUT_LINE( file => l_utl_id
34 , buffer => l_header );
35
36 UTL_FILE.FCLOSE(file => l_utl_id);
37
38 DBMS_OUTPUT.PUT_LINE( LENGTH( l_header ) );
39 End;
40 /
27500
PL/SQL procedure successfully completedHope this helps,
Christian Balz
Similar Messages
-
Invalid_path exception while using UTL_FILE.FOPEN
Hi
I am getting invalid_path exception while using the UTL_FILE.fopen subprogram. I tried finding out the reason but could not solve it. Please help.
Below is my piece of code.
create directory utldr as 'e:\utldir';
declare
f utl_file.file_type;
s varchar2(200);
begin
dbms_output.put_line('1');
f := utl_file.fopen('UTLDR','utlfil.txt','r');
dbms_output.put_line('2');
utl_file.get_line(f,s);
dbms_output.put_line('3');
utl_file.fclose(f);
dbms_output.put_line('4');
dbms_output.put_line(s);
exception
when utl_file.invalid_path then
dbms_output.put_line('invalid_path');
end;
the result is:
1
invalid_pathI am executing it from sys. The same user who created the directory.
The output is as below:
SELECT * FROM dba_directories
OWNER DIRECTORY_NAME DIRECTORY_PATH
SYS MEDIA_DIR d:\avale\rel4\demo\schema\product_media\
SYS LOG_FILE_DIR d:\avale\rel4\assistants\dbca\logs\
SYS DATA_FILE_DIR d:\avale\rel4\demo\schema\sales_history\
SYS EMP_DIR E:\Oracle Directory
SYS REMOTED \\10.1.1.12\oracle directory
SYS UTLDR e:\utldir
SELECT * FROM dba_tab_privs WHERE table_name='UTLDR'
GRANTEE OWNER TABLE_NAME GRANTOR PRIVILEGE GRANTABLE HIERARCHY
PUBLIC SYS UTLDR SYS READ NO NO -
Broken korean characters while using utl_file.fopen
Hi,
I have korean data in a table and I need to extract it out.
Am using utl_file.fopen for this. It extracts, but korean characters are coming broken...
Is there some setting (NLS_LANG etc) that I need to do? I tried NLS_LANG korean_korea.KO16KSC5601 but didn't help...
Thanks,
SachinPlease post this question in the Database forum for an appropriate response: General Database Discussions
Regards,
OTN -
Error while using UTL_FILE.FOPEN
sir,
when i write procedure using utl_file.fopen i am getting error as it must be declared PLS-00201. what mistake, i am doing.
yours
dr.s.r.bhattachari was under the impression that there will be a moderator who will redirect the question even by mistake we post? is it not?Absolutely not. On the APEX forum we are in the fortunate position of having members of Oracle's APEX team actively involved, but neither they nor any of the other contributors perform the role of moderator or have administrative access to the forum system. The OTN team who do only really perform "moderation" when there has been a breach of the OTN Terms and Conditions.
If your question has obviously been posted in the wrong forum, or someone thinks you will get a better response elsewhere then generally they'll suggest this, as above. -
Problem in using UTL_FILE.FOPEN with filename containing accent characters
select value from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
VALUE
AL32UTF8
declare
l_output UTL_FILE.FILE_TYPE;
filename varchar2(100) := 'Avenue des Champs-Élysées.txt';
begin
l_output := UTL_FILE.FOPEN ('UPLOAD_DIR', filename, 'W');
utl_file.put_line (l_output, 'Testing');
utl_file.fclose(l_output);
end;
The file in the UPLOAD_DIR becomes "Avenue des Champs-Élysées.txt"
can anyone tell me what NLS settings I should use in order to create file with correct filename ?symplik wrote:
The file in the UPLOAD_DIR becomes "Avenue des Champs-Élysées.txt"And what does the o/s file system support and what is the operating system's NLS settings?
If there is a mismatch between what you do in your code in Oracle, and what the o/s is configured for, then this type of "+translation+" error is to be expected. -
Oracle 9i UTL_FILE.FOPEN throwing READ_ERROR
Hi
while running the package containg UTL_FILE.FOPEN
I am getting an error for reading the file on this statement :
v_file_handler := UTL_FILE.FOPEN(i_directory_path,i_file_name,'R');This happens in UNIX ,LINUX and windows NT server .
kindly suggest , whether this is an OS error (technical problem) or something else .
thanx in advance ,
Ashutosh .Hi
the UTL_FILE.FOPEN only opens an existing flat file on your OS , the UTL_FILE.GET_LINE reads from the file.
many reasons to generate a read error .
the file can be corrupted, the file doesn't exists or you havent configured the UTL_FIL_DIR parameter in the init.ora file which should be on the machine where the database is.
make sure you have the correct file name and the parameter is set.
also try to handle the exception.
WHEN UTL_FILE.READ_ERROR THEN
RAISE_APPLICATION_ERROR (-20204, SQLCODE || ' ' || SQLERRM);
UTL_FILE.FCLOSE(v_filehandle);
like this you can get the exact error code and message.
Regards
Tony G. -
Query Regarding UTL_FILE.fopen() -
Guys hope you all doin well-
I am using Oracle 9i release 2 -
I am having problem while i am trying to open a file using the UTL_FILE builtin package -
I created the directory as well where the file is located, that i want to access
While i am executing the utl_file.fopen function returns record
location in varchar2 ,
filename in varchar2 ,
open_mode in varchar2 ,
max_linesize in binary_integer default
returns the following error ORA-29283: invalid file operation
The description of the error i found is:
ORA-29283: invalid file operation
Cause: An attempt was made to read from a file or directory that does not exist, or file or directory access was denied by the operating system.
Action: Verify file and directory access privileges on the file system, and if reading, verify that the file exists
The file exists and the user has the privileges to access the file too - but still having problems
please help -
if any buddy has the idea please share -
Thanks
Y.V.Hello Y.V.
Have you set the parameter utl_file_dir? Please check. In most of the cases the problem is because of this parameter
You can set it to directory that you want to access. Or else you can set it to * (which means) that UTL_FILE would be able to read from any directory on which Oracle Binary Owner has got access. Please be careful when setting this to *
To check the parameter use query:
select name,value from v$parameter
where name ='utl_file_dir';
Regards
Sudhanshu
OCP DBA -
Cannot create a file using UTL_FILE.FOPEN
Dear All,
I am using this syntax for creating a file in window
i have declare this like this
l_file_id UTL_FILE.file_type;
l_file_name := 'DHL_'||110570284||'_'||TO_CHAR(SYSDATE,'ddmmyyyy')||'.txt'
l_file_id :=UTL_FILE.FOPEN('C:\D2R',l_file_name,'W');
Is this syntax work?
My database version is oralce 10g
ThanksFirst of all, UTL_FILE is PL/SQL package and is executed on database server side, not on client side. Therefore, it is trying to create file in directory C:\D2R on database sefrver. So if you want to create file in directory C:\D2R on your client box - you can't. Next point - you are specifying directory explicitly which old and obsolete syntax. It requires, for security reasons to add C:\D2R to init.ora parameter UTL_FILE_DIR, otherwise UTL_FILE will raise an error. You should use directory objects:
CREATE DIRECTORY dir AS 'C:\D2R';and grant READ/WRITE on it to users. Then use:
l_file_id :=UTL_FILE.FOPEN('DIR',l_file_name,'W'); -- use directory name in upper caseAnd keep in mind, as I already mentioned UTL_FILE is PL/SQL package and is executed on database server side which means it runs under OS user oracle. Therefore OS user oracle must have write permission on C:\D2R.
SY. -
Unable to create file using : =utl_file.fopen
Hi Team,
My issue is file is not getting created, i checked the permissions of the directory.
No error is received while executing the below script .
declare
f1 utl_file.file_type;
begin
f1:=utl_file.fopen('TAX_CODE_OUT_FILE_PATH','test.txt','W');
utl_file.put_line(f1,'memocan');
utl_file.fclose(f1);
end;
Any suggestion why file is not getting created ?i tried the following :
declare
V1 VARCHAR2(32767);
f1 utl_file.file_type;
begin
F1 := UTL_FILE.FOPEN('TAX_CODE_OUT_FILE_PATH','in.txt','R');
UTL_FILE.GET_LINE(F1,V1,32767);
UTL_FILE.FCLOSE(F1);
end;
Error is thrown as following ;
Error report:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 537
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 - "invalid file operation"
*Cause: An attempt was made to read from a file or directory that does
not exist, or file or directory access was denied by the
operating system.
*Action: Verify file and directory access privileges on the file system,
and if reading, verify that the file exists.
Any suggestions ?? -
UTL_FILE.FOPEN in PL/SQL
Hi,
I want to use UTL_FILE.FOPEN in PL/SQL procedure. I keep getting an exception when I try to open the file.
FDebug := UTL_FILE.FOPEN('D:\SQL', 'debug.txt', 'w');
UTL_FILE.PUT_LINE(FDebug, 'Hello World');
UTL_FILE.FCLOSE(FDebug);
I believe the problem is that the directory is inaccessible.
I read in another post that the UTL_FILE_DIR must be set in the init.ora file. However, I do not have an init.ora file. I am willing to add one but do not know how.
Any help would be aprreciated.
Thank You,
Scott
nullUp to 8i, Oracle refused to access a file that is not pointed to in the utl_file_dir parameter in the init<sid>.ora file.
In Oracle 9i, in order to access a file, either the utl_file_dir parameter must be set, or one has to create a directory as create or replace directory dir_temp as 'c:\temp'; -
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 -
Procedure using utl_file.fopen
Hi ,
I want to open a file ,read it line by line and if i find one particular word i want to display the whole line.
I tried writing a procedure but not getting desired output.
DECLARE
x utl_file.file_type;
y varchar2(200);
BEGIN
x:= utl_file.fopen('TRACE1',DB_ora_111_trc.txt','R');
LOOP
BEGIN
UTL_FILE.GET_LINE(x,y);
if x='select' then
dbms_output.put_line(x);
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(x);
END;
Here i am opening a tkprof file and trying to grep for select word and if it is found,display the whole select query.The above is not showing any output.Kindly assist me since i am new to coding.
Thanksuser10698496 wrote:
Hi,
I am getting only these much as my output . I want to see entire select query.DECLARE
f utl_file.file_type;
s varchar2(2000);
BEGIN
f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
LOOP
BEGIN
UTL_FILE.GET_LINE(f,s);
if lower(s) like '%select%' then
dbms_output.put_line(s);
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(f);
END;
SELECT uid,tname,str,acol,hcol,TO__CHAR(u_time,'DD-MM-YYYY
SELECTgroup,name,address1,state,country,fax_no,
PL/SQL procedure successfully completed.
Ok, so that is telling us that you have your queries split over multiple lines?
In that case you need to "switch on" the output of lines from the moment you find a "select" and then switch it off again when you get a line that indicates the end of the select. So let's assume your selects end with a ";" as the last character on the last line of the select, you can do something like this...
DECLARE
f utl_file.file_type;
s varchar2(2000);
in_select boolean;
BEGIN
f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
in_select := false;
LOOP
BEGIN
UTL_FILE.GET_LINE(f,s);
if lower(s) like '%select%' or in_select then
dbms_output.put_line(s);
in_select := not(s like '%;'); -- stop when we get to ";" at end of a line.
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(f);
END;
Also i attempted to cut only table name from the output select query.I tried something like o :=substr(s,instr(s,'from')+4);PFB the code and output.Pls let me know where am i going wrong.
DECLARE
2 f utl_file.file_type;
3 s varchar2(2000);
4 op varchar2(1000);
5 BEGIN
6 f := utl_file.fopen('TRACE_EXTRACT','DB_ora_1118250.trc.txt','R');
7 LOOP
8 BEGIN
9 UTL_FILE.GET_LINE(f,s);
10 if lower(s) like '%select%' then
11 op :=substr(s,instr(s,'from')+4);
12 dbms_output.put_line(op);
13 end if;
14
15 EXCEPTION
16 WHEN NO_DATA_FOUND THEN EXIT ;
17 END;
18 END LOOP;
19 utl_file.fclose(f);
20 END;
21 /
ECT uid,tname,str,acol,hcol,TO__CHAR(u_time,'DD-MM-YYYY
ECTgroup,name,address1,state,country,fax_no,
that's because there is no "from" on those lines, so the result of the instr is 0 and you are adding 4, so you are getting all characters from character 4 onwards.
What you need in conjunction with my above suggestion is something like this...
DECLARE
f utl_file.file_type;
s varchar2(2000);
in_select boolean;
BEGIN
f := utl_file.fopen('TRACE1','DB_ora_1118250.trc.txt','R');
in_select := false;
LOOP
BEGIN
UTL_FILE.GET_LINE(f,s);
if lower(s) like '%select%' or in_select then
dbms_output.put_line(s);
if lower(s) like '%from%' then
dbms_output.put_line('TABLES: '||substr(s,instr(s,'from'+5))); -- +5 to get past the from and the space character after it.
end if;
in_select := not(s like '%;'); -- stop when we get to ";" at end of a line.
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN EXIT ;
END;
END LOOP;
utl_file.fclose(f);
END;
/ -
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 -
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 -
How to create/delete files from filesystem using PL/SQL ? UTL_FILE?
Greetings,
I will start by explaining what i intend to do.
I have an application made in APEX. This application will have among other purposes the managment of pdf files which will reside in the filesystem.
I have questioned the person in charge to keep the pdf files in the database and not in the filesystem but without success.
So the pdf files reside in the filesystem and there is a record in a database table about them. A table keeps all info about the pdf, their location , size and name, creation date etc.
The APEX application will have a mecanism to allow the deletion of the pdf files if an administrator decides.
So it should be possible for an administrator to schedule the deletion of all pdf files whoe creation date is older than 2008 for example
So, how can i achieve that?
After some research i foudn about the UTL_FILE package which seems to have it takes to perform the task in issue.
My idea was to have a script in the operating system which runs nightly and reads a file containing all file names of the pdf to be erased.
The file which contains the names of the pdfs to be erased will be generated by the database a few minutes before.
If there are no pds files to be erased than the file containing the names will simply be empty
Are there any other viable solutions out there?
And as for opening/creating the file withn the pdf names, i use:
UTL_FILE.FOPEN (
location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
And as for writing lines (a pdf name per line ), i use;
UTL_FILE.PUT_LINE (
file IN FILE_TYPE,
buffer IN VARCHAR2,
autoflush IN BOOLEAN DEFAULT FALSE);
is there a better solution?
thanks all.
-> My Homepage <-
Edited by: Igor Carrasco on Apr 14, 2009 3:11 PM
Edited by: Igor Carrasco on Apr 14, 2009 3:12 PMGreetings,
I have read that link above, some questions still though.
I will provide some more information.
-First the database is in a windows server.
The windows server has a virtual drive mounted as z:\ <-- this points to a directory in virtual machine, i can manually access/create/delete files manually,i tested.
-Second utl_file_dir is defined as * , in t that enough to cover mounted drives? ( i can't change the init.ora and reboot the db right now :( gotta wait.. )
Do i explicitly have to define utfl_file_dir = z: ?
-Third haven't had the chance to test it on linux or any other operating system, assuming a virtual unit is mounted successfully and that the issues above are solved i should be able to operate on any mounted drive whatever the os, right?
Best regards
Maybe you are looking for
-
Displaying iTunes radio information in Apple Menu Bar
I know that you can get software and plug-ins which show song information etc in the Apple Menu Bar so you don't have to keep switching back to iTunes to see what is being played - but can this be done for radio broadcast information? The software I'
-
Can we get satellite internet on ipod 4th generation?
can we get satellite internet on ipod 4th generation?
-
Been a customer since 2003 and been eligible for an upgrade since 2011. We finally upgraded our phone for better voice quality service. $149.00 for a basic phone, but it's for business and that's what we need. We got lucky by surfing online and using
-
I am adapting the Flash Form Real Estate tutorial and I am real close to getting everything working. Upon inserting a new listing it puts it in the MS SQL correctly but adds a blank row in the grid. If you refresh it shows up correctly. The only diff
-
Scrollview with Tableview, Tableviewcell touch feedback question
I am trying to make a scrollview with some tableview in it so that I can slide new tableview with drag&slide. Does anyone know if this is all possible? I tried to implement this but scrollview blocks all the event and doesn't let the table view to sc