Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: utl_file and newline?

Re: utl_file and newline?

From: Simon Hall <Simon.Hall_at_logicacmg.com>
Date: Tue, 11 Feb 2003 10:43:44 +0000
Message-ID: <3E48D3E0.353E0380@logicacmg.com>

I've always found utl_file to be a pain for various reasons - line length limits, newlines etc and don't use it for anything more than log files now.

As I understand it utl_file works by putting the text you're writing (with put or put_line) into a buffer (of very limited size). Then when you write a new line (either explicitly with new_line or implicitly at the end of a put_line call) the buffer is flushed to disk and a new line written. This flush/new line also happens when you close the file if there's anything left in the buffer.

I had to produce some strictly formatted files recently on a windows system but with UNIX style line endings. I gave up with utl_file and wrote a java stored procedure instead. The downside is you've got to use 8i or later and need to install java support into your database.

HTH, Simon

Tim X wrote:
>
> Today I discovered something about utl_file and I just wanted to check
> with others to verify I'm right - my conclusion seems correct, but I
> find it difficult to believe this is the real behavior.
>
> I had a job where I need to create a file from data in the database
> which has a specific format - lines must be EXACTLY 120 characters
> long and the last line must NOT have a newline at the end.
>
> I initially thought utl_file would be fine for this as it has both
> put, put_line and new_line procedures. However, it seems for some
> difficult to understand logic that the fclose procedure will always
> append a newline if one does not exist. I find this strange - why give
> you control over the adding of newlines if the bloody package will
> just go and stick one on the end wether you want ti or not!
>
> Has anyone else found this or is there something I'm missing? I've
> tried some experiments and from what I can work out, fclose will
> always add a newline at the end if one does not exist.
>
> I've now come to the conclusion the only way I will be able to create
> this file is to write my data to a temporary table and then try
> creating the file as I want it via spool from within sqlplus. Anyone
> with a better solution?
>
> Tim
>
> --
> Tim Cross
> The e-mail address on this message is FALSE (obviously!). My real e-mail is
> to a company in Australia called rapttech and my login is tcross - if you
> really need to send mail, you should be able to work it out!
Received on Tue Feb 11 2003 - 04:43:44 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US