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!
Johan
The 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
Similar Messages
-
UTL_FILE, Extra CRFL's, possible OS interpretation problem.
Greetings,
DISCLAIMER:
I am an oracle noob so if I make a mistake in forum etiquette or have not checked all available documentation or have made an assumption that is incorrect ( or noobish ) or am unaware of a tool better suited to the task I am trying to accomplish..
Please don’t flame me, I am learning. Give me constructive replies and I will learn, I promise.
My environment: 10G XE DB running on Server 2k3. Developing in SQLDEV 1.54
I am attempting to dump the contents of a CLOB to a file on the OS disc. Due to formatting restrictions, the contents of the file written to disc must be EXACTLY the contents of the CLOB, character per-per character, verbatim.
Here is an example anon block that will give you the essentials of the way I am attempting to accomplish this:
DECLARE
l_clob CLOB ;
l_output_file utl_file.file_type;
BEGIN
l_clob := 'Hello my name is George!' || chr(13) || chr(10) ;
l_clob:= l_clob || 'Would you like to play a game?' || chr(13) || chr(10);
l_clob := l_clob || 'It will be fun, I promise..' || chr(13) || chr(10);
dbms_output.put_line( dbms_lob.getlength(l_clob));
l_output_file := utl_file.fopen( TEST_DIR' , 'test.txt' ,'W', max_linesize=> 32767 );
utl_file.put( l_output_file , l_clob );
utl_file.fflush( l_output_file);
utl_file.fclose( l_output_file );
utl_file.fclose_all;
END;
Here you can see where I put a few lines into my clob, I manually append the CRLF using the CHR function, since I cant accurately reproduce a non-printable character in a string value. This is important because the Clob I am attempting to write to disc contains CRLF’s as part of its data, these must be preserved. Also note that I am writing this to the file using utl_file.PUT not PUT_LINE, again, because the disk file must be the clob verbatim, I cant use put_line because it adds a “new line character” at the end of the data it writes.
Ignore the DMBS_OUTPUT line , I will get back to that in a bit.
I execute this bit of code and get a file text.txt. What I expected to see was:
“'Hello my name is George!
Would you like to play a game?
'It will be fun, I promise..”
What I actually got was:
!http://i594.photobucket.com/albums/tt22/GargleSpam/Temp001.jpg!
Looking at this in notepad++ we can expose the non-printable chars:
!http://i594.photobucket.com/albums/tt22/GargleSpam/Temp002.jpg!
Using notepad ++ we can see that an extra CR ( CHR(13)) has been pre-pended to the CRLF. We can confirm this is not an artifact of viewing this in notepad by looking at the file size of the output file and comparing it to the size of the clob.
The DBMS_OUTPUT line indicates ( in my test case) clob size of 87 characters. If you take the time to count you will see this is correct. 81 printable characters that we see, and the 6 non-printable chars to accomplish the CRLF’s.
However if we look at the file size:
!http://i594.photobucket.com/albums/tt22/GargleSpam/Temp003.jpg!
So that’s 87 + our 3 “ninja ” CR’s.
For my purposes this is a deal-breaking problem. The contents of my output file must be exactly the contents of my clob, byte for byte. So this extra CR is a big big problem.
Where is it coming from? I started thinking about the “new line character” that the PUT_LINE procedure uses and, had a hunch that perhaps since the DB is OS independent, it might be passing one of the non-printable chars to the OS as “new line” and letting the os worry about what that means on disk. With that in mind I did some further testing:
DECLARE
l_clob CLOB ;
l_output_file utl_file.file_type;
BEGIN
l_clob := 'Incoming lf->'|| chr(10) ;
l_clob:= l_clob || 'Incoming cr->' || chr(13);
clob:= lclob || 'Incoming CRLF->' || chr(13) || chr(10);
l_output_file := utl_file.fopen( TEST_DIR' , 'test.txt' ,'W', max_linesize=> 32767 );
utl_file.put( l_output_file , l_clob );
utl_file.fflush( l_output_file);
utl_file.fclose( l_output_file );
utl_file.fclose_all;
END;
This code results in:
!http://i594.photobucket.com/albums/tt22/GargleSpam/Temp004.jpg!
Looking at this it becomes obvious that the CHR(10) is being written to disc as TWO characters ( CR LF). So my assumption must be correct, that the DB is passing CHR(10) to the OS as “newline” and the OS ( Windows in my case ) is interpreting this as ‘CRLF.’
This makes sense since it seems to be widely known ( though not to me , I am shaky on this part ) that “newline” in unix is just CHR(10), and in windows its CHR(10)||CHR(13).
So I seem to have isolated my problem. Now finally my question.. How to I get around this?
Google searches and searches on this forum yeilded only marginal help, something about passing this file through an FTP server.. ?. The only marginal help was in post # 3298335. Nothing that really answers my question though.
Is there a setting my DBA can set to change this behavior? Is there a different way ( PLSQL) to write the file that might mitigate this? Don’t say put the DB on unix, that’s not an option.
Let me know what you think…
-VAFHi,
Also you should check that the directory name is enclosed between '. TEST_DIR is an Oracle directory object that maps a real directory path in the filesystem (check privileges).
Like:
DECLARE
l_clob CLOB;
l_output_file utl_file.file_type;
BEGIN
l_clob := 'Hello my name is George!' || CHR(13) || CHR(10);
l_clob := l_clob || 'Would you like to play a game?' || CHR(13) || CHR(10);
l_clob := l_clob || 'It will be fun, I promise..' || CHR(13) || CHR(10);
dbms_output.put_line(dbms_lob.getlength(l_clob));
l_output_file := utl_file.fopen('TEST_DIR', 'test.txt', ' W', max_linesize => 32767);
utl_file.put(l_output_file, l_clob);
utl_file.fflush(l_output_file);
utl_file.fclose(l_output_file);
END;Tip: to post formatted code you must enclose it between {noformat}{noformat} tags (start and end tags are the same).
Regards, -
Problem with access rights by using UTL_FILE
Hi all,
Could you please help me with the following problem. A search on this forum did not result in the final solution:
- We are using an Oracle XE database on an Oracle VM instance
- I want to export a lot of data to the filesystem, by using UTL_FILE.
- The package that calls UTL_FILE, should be installed in the database schema 'XXCUST'.
- I have created a folder '/home/oracle/XX_EXPORT_FOLDER' on the filesystem
- I have created a database directory 'XX_EXPORT', which links to this folder
- I have granted read and write to public for this folder
- I use the following script to export the files:
DECLARE
l_file_handle UTL_FILE.FILE_TYPE;
BEGIN
l_file_handle := UTL_FILE.FOPEN( location => 'XX_EXPORT', filename => 'test.txt',open_mode => 'W', max_linesize => 100);
UTL_FILE.PUT_LINE(l_file_handle, 'TEST');
UTL_FILE.FCLOSE(l_file_handle);
END;
When I run this script with the user 'XXCUST' I get the following error:
ORA-06521: PL/SQL: Error mapping function
ORA-06512: at "SYSTEM.UTL_FILE", line 41
ORA-06512: at "SYSTEM.UTL_FILE", line 478
ORA-06512: at line 15
06521. 00000 - "PL/SQL: Error mapping function"
*Cause: An error was detected by PL/SQL trying to map the mentioned
function dynamically.
*Action: Check the stacked error (if any) for more details.
When I run this script with the user 'sys as sysdba', I don't get any errors. My testfile is created successfully.
What should I do to use this script with user XXCUST?What are the permissions on this folder:
/home/oracle/XX_EXPORT_FOLDER -
How pass a parameter with forward slash to plsql script
Hi,
I am trying pass a parameter to plsql script from command line using sqlplus, and the parameter is a file directory and has '/'. Seems the system couldn't recognize the value.
here is my code in DECLARE:
l_FileDir VARCHAR2(200) := &&FileDir ;
I pass value '/usr/tmp' (with the single quote in the string)
Can someone tell me how I do it?
Thanks,
Kate
Edited by: user12100435 on Feb 25, 2010 8:31 AMuser12100435 wrote:
I think you are right. The issue is not file-separator character issue. because the exact same script run in another envoironment. And it's not file directory or permission issue because if I use hardcoded value, the code works fine.
The error message is invalid File directory.
Here is the related part of the code.
-- open file handler
IF UTL_FILE.IS_OPEN(l_FileHandler) THEN
UTL_FILE.FCLOSE(l_FileHandler);
ELSE
l_FileHandler := UTL_FILE.FOPEN ( location => l_FileDir,
filename => l_FileName,
open_mode => 'W',
max_linesize => 32767 );
END IF;Ok, based on your input so far, I have cooked up a simple testcase.
Make sure you are doing something similar to this -
test@XE>
test@XE> -- show the contents of the anonymous PL/SQL script
test@XE> -- You are probably passing two parameters - the file location and the file name
test@XE> --
test@XE> ! cat test5.sql
DECLARE
l_FileHandler UTL_FILE.FILE_TYPE;
l_FileDir VARCHAR2(200) := '&1' ;
l_FileName VARCHAR2(200) := '&2' ;
BEGIN
-- open file handler
IF UTL_FILE.IS_OPEN(l_FileHandler) THEN
UTL_FILE.FCLOSE(l_FileHandler);
ELSE
l_FileHandler := UTL_FILE.FOPEN ( location => l_FileDir,
filename => l_FileName,
open_mode => 'W',
max_linesize => 32767 );
UTL_FILE.PUT_LINE(file => l_FileHandler, buffer => 'Hello, World!');
UTL_FILE.FCLOSE(file => l_FileHandler);
END IF;
END;
test@XE>
test@XE> -- execute it
test@XE> @test5.sql '/usr/tmp' 'first.txt'
old 3: l_FileDir VARCHAR2(200) := '&1' ;
new 3: l_FileDir VARCHAR2(200) := '/usr/tmp' ;
old 4: l_FileName VARCHAR2(200) := '&2' ;
new 4: l_FileName VARCHAR2(200) := 'first.txt' ;
DECLARE
ERROR at line 1:
ORA-29280: invalid directory path
ORA-06512: at "SYS.UTL_FILE", line 33
ORA-06512: at "SYS.UTL_FILE", line 436
ORA-06512: at line 10
test@XE>
test@XE> -- Create a directory object that points to "/usr/tmp"
test@XE> create directory log_dir as '/usr/tmp';
Directory created.
test@XE>
test@XE> -- now invoke the script
test@XE> -- Note - I pass the value "LOG_DIR" in uppercase. That's the name of my directory object.
test@XE> --
test@XE> @test5.sql 'LOG_DIR' 'first.txt'
old 3: l_FileDir VARCHAR2(200) := '&1' ;
new 3: l_FileDir VARCHAR2(200) := 'LOG_DIR' ;
old 4: l_FileName VARCHAR2(200) := '&2' ;
new 4: l_FileName VARCHAR2(200) := 'first.txt' ;
PL/SQL procedure successfully completed.
test@XE>
test@XE> -- Since my Oracle client is on the same machine as the Oracle server, I can check
test@XE> -- this file "/usr/tmp/first.txt" quite easily
test@XE>
test@XE> ! cat /usr/tmp/first.txt
Hello, World!
test@XE>
test@XE> isotope -
Hi,
My task functionality:
I have a file with data and it has to check with against database,
if it finds data then update in database otherwise write in a logfile.
The problem is when it doesn't find the match, the control is going in the inner block of
exception but it is not writing into a file, where i specified as Utl_file.put_line.
(getting 0KB file size).
CAn you please, help me...
Here is my code:
table INDV
===========
create table INDV(id number(5));
insert into indv values(62216);
insert into indv values(62217);
insert into indv values(62218);
insert into indv values(62219);
insert into indv values(62220);
import.txt file
===============
62216,#~
62215,#~
62218,#~
62217,#~
62220,#~
62219,#~
log File
==========
62215,#~
procedure
=============================================
CREATE OR REPLACE PROCEDURE import_file
IS
file_dir VARCHAR2(80) := 'D:\work\';
file_name VARCHAR2(200) := 'log_import'||'_'||to_char(SYSDATE,'YYMMDD')||'.txt';
file_mode CHAR(1) := 'W';
max_linesize NUMBER(10) := 12000;
filehandle UTL_FILE.FILE_TYPE;
input_file UTL_FILE.file_type;
input_buffer VARCHAR2(2000);
PATH VARCHAR2(200) := 'D:\work\';
filename VARCHAR2(400) := 'import.txt';
counter NUMBER := 0;
vDcf_id NUMBER(5);
BEGIN
filehandle := UTL_FILE.FOPEN(file_dir, file_name, 'W', max_linesize);
input_file := UTL_FILE.fopen (PATH, filename, 'R');
LOOP
UTL_FILE.GET_LINE(input_file, input_buffer);
vDcf_id := SUBSTR(input_buffer,1,instr(input_buffer,',#~')-1);
DBMS_OUTPUT.put_line ('YOU ARE IN OUTER LOOOP...'||TO_CHAR(vDcf_id));
DECLARE
V_ID INDV.ID%TYPE;
BEGIN
SELECT ID INTO V_ID
FROM INDV WHERE ID = vDcf_id;
DBMS_OUTPUT.put_line ('YOU ARE IN INSIDE LOOOP...'||TO_CHAR(V_ID)||' '||
'vDcf_id'||TO_CHAR(vDcf_id));
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.put_line ('excetion input_buffer...'||input_buffer);
UTL_FILE.PUT_LINE(filehandle, vDcf_id);
END;
counter := counter + 1;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
null;
WHEN OTHERS
THEN
UTL_FILE.fclose (input_file);
UTL_FILE.fclose (filehandle);
raise_application_error (-20056,SQLCODE||':'||SQLERRM);
END;
Thanks in advance.BEGIN
filehandle := UTL_FILE.fopen (file_dir, file_name, 'W', max_linesize);
input_file := UTL_FILE.fopen (PATH, filename, 'R');
LOOP
UTL_FILE.get_line (input_file, input_buffer);
vdcf_id := SUBSTR (input_buffer, 1, INSTR (input_buffer, ',#~') - 1);
DBMS_OUTPUT.put_line ('YOU ARE IN OUTER LOOOP...' || TO_CHAR (vdcf_id));
DECLARE
v_id indv.ID%TYPE;
BEGIN
SELECT ID
INTO v_id
FROM indv
WHERE ID = vdcf_id;
DBMS_OUTPUT.put_line ( 'YOU ARE IN INSIDE LOOOP...'
|| TO_CHAR (v_id)
|| ' '
|| 'vDcf_id'
|| TO_CHAR (vdcf_id)
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('excetion input_buffer...' || input_buffer);
UTL_FILE.put_line (filehandle, vdcf_id);
RAISE;
END;
counter := counter + 1;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
UTL_FILE.fclose (input_file);
UTL_FILE.fclose (filehandle);
raise_application_error (-20056, SQLCODE || ':' || SQLERRM);
END;
/ -
Character set Conversion problem
Hello
I have a problem in converting AL32UTF8 character set to AR8MSWIN1256 ,We have two databases in linux suppose
db1 and db2 , I have a procedure in db2 that connect to db1 by a database link and extract records from a table
in db1 database and save them in a file , at this process I user CONVERT function for converting AL32UTF8 characters to AR8MSWIN1256 but when I open that file by any editor in Microsoft Windows it show me unreadable characters,I must mention that the table has Farsi (Persion) characters and Persion characters are unreadable
in db1 database NLS_CHARACTERSET=AL32UTF8 and NLS_NCHAR_CHARACTERSET=AL16UTF16
in db2 database NLS_CHARACTERSET=AL32UTF8 and NLS_NCHAR_CHARACTERSET=UTF8
db1 is oracle10 and db2 is oracle9i
the table structure is like it
CREATE TABLE "ALI"."STMP"
( "P_EXCHANGECODETRADER" VARCHAR2(8),
"P_NEGOUSLOGIN" VARCHAR2(40),
"I_BIC_CODE" VARCHAR2(11),
"P_NEGOLIBELLE" VARCHAR2(60),
"DAT" DATE DEFAULT trunc(sysdate),
"SEQ" NUMBER(15,0),
"OPERATION" CHAR(1))
and the procedure is :
create or replace procedure khosravi.traders_changes_file2(code_page varchar2:='AR8MSWIN1256')
as
ft UTL_FILE.FILE_TYPE;
head varchar2(3000 );
line varchar2(3000 );
tail varchar2(3000 );
temp char(3000 char);
c_date date;
counter pls_integer:=0;
function repeat_char(inp char,repeat pls_integer) return varchar2
as
res varchar2(2000 char):='';
begin
if (LENGTH(inp)*repeat) > 2000 then
raise_application_error(-20101, 'the length is bigger than 2000');
end if;
for i in 1..repeat loop
res:=res || inp;
end loop;
return(res);
end repeat_char;
begin
c_date:=sysdate;
head:='01' || 'DEALER' || repeat_char(' ',18) ||to_char(c_date,'YYYYMMDD')||
to_char(c_date,'hh24miss') ;
temp:=head;
ft:=UTL_FILE.fopen(location => 'TEST_DIR',filename => 'ali_'||code_page,open_mode => 'w',max_linesize => 3000);
UTL_FILE.PUT_LINE(file => ft,buffer =>convert(trim(temp),code_page) );
for rec in (select city,p_exchangecodetrader,p_negouslogin,i_bic_code,p_negolibelle,dat,operation from traders_changes@db1) loop
line:='12' || 'DEALER' || repeat_char(' ',18) ||to_char(c_date,'YYYYMMDD')|| to_char(c_date,'hh24miss')
|| rec.p_exchangecodetrader || repeat_char(' ',8-length(rec.p_exchangecodetrader))
|| rec.p_negolibelle || repeat_char(' ',50-length(rec.p_negolibelle))
|| substr(rec.p_exchangecodetrader,1,3) || ' '
|| substr(rec.p_exchangecodetrader,1,3) || ' '
|| substr(rec.p_exchangecodetrader,6,3)
|| rec.i_bic_code || repeat_char(' ',11-length(rec.i_bic_code))
|| substr(rec.p_negouslogin,1,8)
|| repeat_char(' ',14)
|| 'I'
|| repeat_char(' ',4)
|| repeat_char(' ',10)
|| ' '
||' '
||' '
|| repeat_char(' ',40)
|| repeat_char(' ',40)
|| repeat_char(' ',40)
|| repeat_char(' ',5)
|| rec.city || repeat_char(' ',40-length(rec.city))
|| repeat_char(' ',28)
|| repeat_char(' ',15)
|| repeat_char(' ',15)
|| repeat_char(' ',10)
|| rec.operation
temp:=line;
UTL_FILE.PUT_LINE(file => ft,buffer =>convert(trim(temp),code_page) );
counter:=counter+1;
end loop;
for rec in (select city,p_exchangecodetrader,p_negouslogin,i_bic_code,p_negolibelle,dat,operation from traders_changes@db1) loop
line:='13' || 'DEALER' || repeat_char(' ',18) ||to_char(c_date,'YYYYMMDD')|| to_char(c_date,'hh24miss')
|| rec.p_exchangecodetrader || repeat_char(' ',8-length(rec.p_exchangecodetrader))
|| substr(rec.p_exchangecodetrader,1,3) || ' '
|| substr(rec.p_exchangecodetrader,1,3) || ' '
|| substr(rec.p_exchangecodetrader,6,3)
|| repeat_char(' ',151)
temp:=line;
UTL_FILE.PUT_LINE(file => ft,buffer =>convert(trim(temp),code_page) );
counter:=counter+1;
end loop;
counter:=counter+2;
tail:='99'||'DEALER' || repeat_char(' ',18)
|| to_char(c_date,'YYYYMMDD')
|| to_char(c_date,'hh24miss')
|| repeat_char('0',9-length(to_char(counter)))
|| to_char(counter);
temp:=tail;
UTL_FILE.PUT_LINE(file => ft,buffer =>convert(trim(temp),code_page) );
UTL_FILE.fclose(ft);
end;
Do you know what is problem or do you know better solution ?
Thankshttp://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions027.htm#SQLRF00620 might be of some help
Take a look at oracle clients you are connecting from too (I'm not experienced as I don't have privileges to do anything regarding the operating system)
Regards
Etbin -
procedure insert_rec is
BEGIN
for cur in (select title from new_books)
loop
insert into book ( title) values (cur.title);
insert into book(book_id) values (seq_book_id.NEXTVAL);
end loop;
commit;
END;
I got the following erros when i executed the procedure insert_rec:(I did not pass any arguments for the preocedure).Can we give a value for the book_id using the insert_rec procedure
ORA-01400: cannot insert NULL into ("LIBRARY"."BOOK"."BOOK_ID")
ORA-06512: at "LIBRARY.HWK3", line 136
ORA-06512: at line 2
Regards,
Gita.Given below is my whole package:
CREATE OR REPLACE
package body hwk3 is
fid UTL_FILE.FILE_TYPE ;
procedure generate_ra_catalog is
cnt NUMBER ;
begin
/* setup output file */
fid := UTL_FILE.FOPEN( location => 'DATA_OUTPUT',
filename => 'CATALOG.DAT',
open_mode => 'w',
max_linesize => 4026);
UTL_FILE.PUT_LINE( fid, '7') ; -- start of catalog specifying 7 tables
for tab in ( select table_name from user_tables
where table_name in ( 'BOOK','BOOK_COPIES','BOOK_AUTHORS','BOOK_LOANS',
'BORROWER','LIBRARY_BRANCH','PUBLISHER','NEW_BOOKS')
loop
UTL_FILE.PUT_LINE( fid, tab.table_name ) ;
select count(*) into cnt from user_tab_columns where table_name = tab.table_name ;
UTL_FILE.PUT_LINE( fid, to_char(cnt) ) ;
for col in ( select column_name,
decode(data_type,'NUMBER','INTEGER',
'DATE','VARCHAR',
'VARCHAR2','VARCHAR',
'VARCHAR' ) ra_data_type
from user_tab_columns
where table_name = tab.table_name
order by column_id
loop
UTL_FILE.PUT_LINE( fid, col.column_name ) ;
UTL_FILE.PUT_LINE( fid, col.ra_data_type ) ;
end loop ;
end loop ;
/* close file */
UTL_FILE.FCLOSE( fid ) ;
exception
when OTHERS then
dbms_output.put_line( '*** ERROR *** Internal error' ) ;
dbms_output.put_line( '[' || SQLCODE || '] ' || SQLERRM ) ;
/* close file */
UTL_FILE.FCLOSE( fid ) ;
end ;
procedure generate_ra_datafile ( v_table varchar2 ) is
cur INTEGER := DBMS_SQL.OPEN_CURSOR;
fdbk INTEGER ;
rec_cnt NUMBER ;
col_cnt NUMBER ;
data varchar2(4096) ;
begin
/* setup output file */
fid := UTL_FILE.FOPEN( location => 'DATA_OUTPUT',
filename => upper(v_table) || '.DAT',
open_mode => 'w',
max_linesize => 4026);
execute immediate 'select count(*) from ' || v_table
into rec_cnt ;
UTL_FILE.PUT_LINE( fid, to_char(rec_cnt) ) ; -- start of data file specifying cnt records
-- YOUR CODE HERE TO CREATE DATA FILES
/* close file */
UTL_FILE.FCLOSE( fid ) ;
exception
when OTHERS then
dbms_output.put_line( '*** ERROR *** Internal error' ) ;
dbms_output.put_line( '[' || SQLCODE || '] ' || SQLERRM ) ;
/* close file */
UTL_FILE.FCLOSE( fid ) ;
end ;
procedure load_xml ( xmlfile varchar2 ) is
begin
insert into XMLDOC
values ( XMLTYPE ( bfilename( 'DATA_INPUT', xmlfile ), nls_charset_id('AL32UTF8') ) ) ;
exception
when OTHERS then
dbms_output.put_line( '*** ERROR *** Internal error' ) ;
dbms_output.put_line( '[' || SQLCODE || '] ' || SQLERRM ) ;
end ;
procedure generate_ra_database is
begin
-- generate catalog file
generate_ra_catalog ;
-- generate data files
for tab in ( select table_name from user_tables
where table_name in ( 'BOOK','BOOK_COPIES','BOOK_AUTHORS','BOOK_LOANS',
'BORROWER','LIBRARY_BRANCH','PUBLISHER','NEW_BOOKS')
loop
generate_ra_datafile ( tab.table_name ) ;
end loop ;
exception
when OTHERS then
dbms_output.put_line( '*** ERROR *** Internal error' ) ;
dbms_output.put_line( '[' || SQLCODE || '] ' || SQLERRM ) ;
end ;
procedure insert_rec (new_book_id number) is
BEGIN
for cur in (select title from new_books where new_id = new_book_id)
loop
insert into book ( book_id, title) values (seq_book_id.NEXTVAL, cur.title);
end loop;
commit;
END;
end ; -
Urgent: Search all fields
Hi,
I've a problem.
My job is to search a value which can stand in each field from each table.
There are 1054 tables and i should write a procedure which can look in each field if the value is 77669.
It's very urgent.
Thanks in advance.
With best regards
NicoleThanks i've solved the problem, but now i have an other problem.
I've to find colums which have different or the same value and if a column have the only one value in each field i want to know this value.
I've tried this procedure but i get a error message:
invalid cursur!
RIS5COLUMNS is a view which have all table_names, column_names,datatypes and max_value.
Here is the procedure:
Create or replace procedure analyse is
lob_length integer;
read_amount integer;
read_offset integer;
buffer varchar2(100);
loc varchar2(100) := 'usr_dir';
f_hand utl_file.file_type;
datatyp varchar2(20);
counter number;
value VARCHAR2(200);
tab_nam VARCHAR2(30);
col_nam VARCHAR2(31);
TYPE RefCurTyp is REF CURSOR;
CV REFCURTYP;
sql_statement VARCHAR2(2000);
max_len number(10);
Cursor cur_suche is
Select column_name,upper_table_name,dbms_type_string,char_max_length from RIS5COLUMNS
where upper_table_name in (Select table_name from user_tables);
BEGIN
read_offset := 1;
read_amount := 49;
-- read_amount := 81;
--Opening file
f_hand := Utl_File.Fopen(location =>'d:\oracle\utl_file\',
filename =>'analyse_Linz_AG.txt',
open_mode =>'w',
max_linesize => 32767);
utl_file.putf(f_hand,'Tabellenname;Feldname;Anzahl unterschiedlicher Einträge;Wert;Max. Länge');
Utl_File.New_Line (f_hand,1);
OPEN cur_suche;
LOOP
FETCH cur_suche into col_nam,tab_nam,datatyp,max_len;
exit when cur_suche%NotFound;
If datatyp <> 'date' then
sql_statement := 'SELECT DISTINCT( COUNT ('||col_nam||')) from '||tab_nam||'';
open CV for sql_statement;
loop
fetch cv into counter;
Close CV;
If value = 1 Then
sql_statement := 'SELECT DISTINCT '||col_nam||' from '||tab_nam||'';
open CV for sql_statement;
fetch cv into value;
utl_file.putf(f_hand,''||tab_nam||';'||col_nam||';'||counter||';'||value||';'||max_len||'');
Utl_File.New_Line (f_hand,1);
Else
utl_file.putf(f_hand,''||tab_nam||';'||col_nam||';'||value||';;'||max_len||'');
Utl_File.New_Line (f_hand,1);
End if;
END LOOP;
Close CV;
End if;
END LOOP;
Close cur_suche;
utl_file.fclose(f_hand);
end analyse; -
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 -
Error writing data in a flat file using UTL_FILE feature
Hi All,
I have written a package which fetches data from four different cursors and inserts into a temporary table.
Now this temporary table is used to write data in a file using the UTL_FILE feature.
fhandler :=
UTL_FILE.fopen (l_path,'Demand_Transactions_'
|| TO_CHAR (SYSDATE, 'YYYYMMDDHH24MI')
|| '.txt',
'w',
max_linesize => 32767
This table has 62593 records and when it starts writing data into the file from the table it errors out after writing 30045 records with the error - ORA-01722: invalid number.
Can anyome please advise me is it because of the max_linesize => 32767. If not then what can be the possible reason.
Any help in this would be highly appreciated.
Regards,
Shruti891330 wrote:
Hi All,
I have written a package which fetches data from four different cursors and inserts into a temporary table.
Now this temporary table is used to write data in a file using the UTL_FILE feature.
fhandler :=
UTL_FILE.fopen (l_path,'Demand_Transactions_'
|| TO_CHAR (SYSDATE, 'YYYYMMDDHH24MI')
|| '.txt',
'w',
max_linesize => 32767
This table has 62593 records and when it starts writing data into the file from the table it errors out after writing 30045 records with the error - ORA-01722: invalid number.
Can anyome please advise me is it because of the max_linesize => 32767. If not then what can be the possible reason.Max linesize is the number of characters in a line before a newline has to be issued, not the number of rows written.
The error would indicate that you have a character to number conversion going on somewhere but the characters are not numeric so it's failing that conversion.
This doesn't sound like a UTL_FILE issue, but more to do with how you are building up your strings to output to the file.
You would need to show us your code that builds up the lines you are writing out, with details of the datatypes of any of the columns/variables included in that. -
UTL_file Procedure- some error on invalid directory path
Hi,
I Created a file procedure...but while executing a procedure its showing directory Error....
Find the solution and post it...
Heading 2: h2. ERROR -29280ORA-29280: invalid directory path
create or replace
PROCEDURE HELLOFLE IS
v_MyFileHandle UTL_FILE.FILE_TYPE;
BEGIN
v_MyFileHandle := UTL_FILE.FOPEN('C:\','HELLO.TXT','a');
UTL_FILE.PUT_LINE(v_MyFileHandle,'Hello World! ' || TO_CHAR(SYSDATE,'MM-DD-YY HH:MI:SS AM'));
UTL_FILE.FCLOSE(v_MyFileHandle);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR ' || TO_CHAR(SQLCODE) || SQLERRM);
NULL;
END;This is the spec of fopen:
UTL_FILE.FOPEN (
location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2,
max_linesize IN BINARY_INTEGER)
RETURN file_type;
Location is not "c:\" but a directory object name. See the pl/sql manual:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_file.htm -
Use of UTL_FILE package
Hi,
I am trying to use the following command:
UTL_FILE.FOPEN('/HOME/SCMS/DUNNING/OUTPUT/','DUNNING_ACCT_YYYYMMDD.PSC','W');
however i get an error invalid directory name.
can anyone please advise how to assign the location as the name of a local directory eg....D:\xyzYou need to use CREATE DIRECTORY statement to create a directory and use that name in fopen.
SQL> CREATE DIRECTORY mydir AS '/appl/gl/log';
SQL> GRANT READ ON DIRECTORY mydir TO DBA;
DECLARE
V1 VARCHAR2(32767);
F1 UTL_FILE.FILE_TYPE;
BEGIN
-- In this example MAX_LINESIZE is less than GET_LINE's length request
-- so the number of bytes returned will be 256 or less if a line terminator is seen.
F1 := UTL_FILE.FOPEN('MYDIR','MYFILE','R',256);
UTL_FILE.GET_LINE(F1,V1,32767);
UTL_FILE.FCLOSE(F1);
-- In this example, FOPEN's MAX_LINESIZE is NULL and defaults to 1024,
-- so the number of bytes returned will be 1024 or less if a line terminator is seen.
F1 := UTL_FILE.FOPEN('MYDIR','MYFILE','R');
UTL_FILE.GET_LINE(F1,V1,32767);
UTL_FILE.FCLOSE(F1);
-- In this example, GET_LINE doesn't specify a number of bytes, so it defaults to
-- the same value as FOPEN's MAX_LINESIZE which is NULL in this case and defaults to 1024.
-- So the number of bytes returned will be 1024 or less if a line terminator is seen.
F1 := UTL_FILE.FOPEN('MYDIR','MYFILE','R');
UTL_FILE.GET_LINE(F1,V1);
UTL_FILE.FCLOSE(F1);
END; This is an example from Oracle docs. You better go through that first.
Cheers
Sarma. -
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... -
Problem in writiing data to UTL_File
Hello Friends,
I'm using UTL_FILE to write the data into csv file, but in the table 1 description column is there which contains 3000 characters.
My problem is i'm not able to write more than 750 characters in csv file and if i tried to do so then get the FILE_WRITE_ERROR. error msg
I tried by breaking the column into 3 different strings by giving the column as diffrent-different aliases but facing the same problem.
Please help me to write all the characters i.e 3000 charcters in a file.
Is there any character length limitation in csv file?
Regards,
AnandAs others have stated MAX_LINESIZE parameter of FOPEN is what matters.
SQL> create table t(c1 varchar2(4000), c2 varchar2(4000))
2 /
Table created.
SQL> insert into t values(rpad('*',4000,'*'),rpad('#',4000,'#'))
2 /
1 row created.
SQL> commit
2 /
Commit complete.
SQL> select length(c1), length(c2) from t
2 /
LENGTH(C1) LENGTH(C2)
4000 4000
SQL> create or replace directory utl_dir as 'e:\oracle\log_files\utl_akivanew'
2 /
Directory created.
SQL> declare
2 lFile_Handle utl_file.file_type;
3 lc1 t.c1%type;
4 lc2 t.c2%type;
5 begin
6 select c1, c2 into lc1, lc2 from t;
7
8 lFile_Handle := utl_file.fopen('UTL_DIR','test.csv','W', 10000);
9
10 utl_file.put_line(lFile_handle, lc1||','||lc2);
11
12 utl_file.fclose(lFile_Handle);
13 end;
14 /
PL/SQL procedure successfully completed.
SQL> declare
2 lFile_Handle utl_file.file_type;
3 lc1 t.c1%type;
4 lc2 t.c2%type;
5 begin
6 select c1, c2 into lc1, lc2 from t;
7
8 lFile_Handle := utl_file.fopen('UTL_DIR','test.csv','W', 7000);
9
10 utl_file.put_line(lFile_handle, lc1||','||lc2);
11
12 utl_file.fclose(lFile_Handle);
13 end;
14 /
declare
ERROR at line 1:
ORA-29285: file write error
ORA-06512: at "SYS.UTL_FILE", line 69
ORA-06512: at "SYS.UTL_FILE", line 604
ORA-06512: at line 12 -
UTL_FILE - file read error
Hi,
I am using UTL_FILE to read one file and write it into other file.
When i am executing procedure that uses UTL_FILE, i get error "ORA-29284: file read error".
I have checked that file exists with all permissions (r,w,e). Is there any limitaion of size to be read by utl_file. my file size is 62 kb.
I have set max_linesize to 32767/
Can anybody tell me the reason why it is happening?can you post the script being used...
What's the database version
A database object called Directory is also needed in database that is created using the create directory command which directs to the folder in the file system. Is that already created?
Regards
Maybe you are looking for
-
In "List View" in a Finder window, among the many column options are "Date created" and "Date modified." In "View Options" (command-J) for any folder, one can add these columns, along with the standard ones "Size," "Kind," "Label," etc. A user can al
-
[picture removed by host] Why does my computer not want to download anything? It says " could not be downloaded". No explanation, or anything! Might be my settings but, Im not real computer savey! Im trying to download the flash player!!!! Help!? T
-
HT4366 Can I use dvi to hdmi for apple tv 3rd generation?
I want to know if the latest generation Apple TV box be connected to my big screen using a DVI on the TV to a HDMI on the Apple TV box?
-
Hello, I'm learning SAP B1 and i'm trying to understand segmented account code information. I understand that a segmented account code looks like: 12100000-01-001-01 where 12100000 is the natural account 01 is a division 001 is a region and the last
-
Enhancing the transaction code WS20000081 - Leave request
Hi all, I have a requirement where i need to use the transaction WS20000081 for creating a leave for those employees who dont have ESS access. I have created a Z program where the employee will login & then use the above mentioned T-code for creating