Home > database >  In the use of utl_file write to a file, a line in the end of the file
In the use of utl_file write to a file, a line in the end of the file

Time:09-28

I am in the process of storage, the data read from the database table, invoke the utl_file put_line to write data in the file,
File is written to an error, but more than a a newline at the end of the file, and if in the following paragraphs toSql tail to join the order by cit_province does not have extra line breaks
Personal guess is that due to caching mechanism of the oracle is just a cache area fill, lead to more than a newline, whether there is solution

Files are generated results:
Don't sort the line

Sorting is not much newline


Code:
ToSql varchar2 (3000);
Linesize BINARY_INTEGER:=30000;
Ifile utl_file. File_type;
Dataline RECORD_SINGLE_ORDER;

The Begin
I_file:=utl_file fopen (file_loc, 'dataFile. TXT', 'w', linesize);
The select CIT_CODE toSql='| | CRH (127) | | CRH (94) | | CIT_PROVINCE | | CRH (127) | | CRH (94) | | CIT_NAME from CITYINFO';

The Open v_cursor for toSql
Loop
The Fetch v_cursor into
Dataline;
Exit the when
V_cursor % NOTFOUND;
Utl_file. Put_line (i_file, convert (dataline data, 'AL32UTF8'), true);
End loop;
The close v_cursor;
Utf_file. Fclose (i_file);
END

Among them:
Type RECORD_SINGLE_ORDER is record (
DATA varchar2 (3000)
);

The create table pub_cityinfo (
Cit_code char (4) not null,
Cit_province char (3) not null,
Cit_name varchar2 (150) not null,
Primaary key (cit_code)
);
  • Related