Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Dani.

Asked: August 22, 2000 - 7:37 am UTC

Last updated: March 15, 2005 - 8:16 am UTC

Version: 8.0.5

Viewed 1000+ times

You Asked

I am using Oracle 8.0 and trying to read a ASCII file using UTL_FILE package. I could find only one function to read contents of a file i.e GET_LINE(). But this function has a limitation. It can only read lines with maximum byte size of 1022.

Is there other work around to read more than 1022 bytes. Or any other packages similar to UTL_FILE?

Can you suggest any other function which can read byte by byte instead of line. ?

Please suggest an answer.
thank you


and Tom said...



With 8.0.5 the limit is 32k.

If you describe the utl_file package, you will see that the fopen procedure is overloaded - the second version takes a parameter MAX_LINESIZE. Set this to a higher number (upto about 32k)....



Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Reading File In Part( paging)

Vikas Sharma, April 01, 2003 - 5:16 pm UTC

Hi Tom,

I have a problem. I am running a procedure which execute the sql commands and add log into a file using utl_file. The procedure run for very long and create a text file of about 400 to 500 mb. I want to read this file in part somthing like paging method. For example i will first read 100 line then next 100 then next 100 and so on.

Kindly tell me the best way to achive. I display the the lines on browser. every thing work fine for small file size about 1 mb and more.

What i would like to achive is paging when reading file. I have alredy adopted your paging method when reading from tables. Kindly suggest.

Thanks,


Regards

Vikas Sharma

Tom Kyte
April 01, 2003 - 7:40 pm UTC

load the file into a table with a sequence per line and forget the file exists?

that would be easiest.

But you could use a BFILE instead in 8i as it supports "seeking", you would have to use dbms_lob.instr and dbms_lob.substr and utl_raw.cast_to_varchar2 -- but it would be doable. Your web page would have to remember the offset to start reading at again when it picked up. see
</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1352202934074 <code>
for an example of what I mean.

In 9i, utl_file supports utl_file.fseek - so you could use that as well. Just remember where you were (fgetpos) and fseek there to resume paging.

Thanks

Vikas Sharma, April 03, 2003 - 1:00 pm UTC

Hi Tom,

Thanks.

Regards,
Vikas Sharma

going back to previous rec wile reading a file

srinivasa rao bachina, May 31, 2003 - 7:41 am UTC

Hi tom ,
i am having file with a set of recs like
aa,fdds.................
bb,.................
bb,.................
bb,.................
aa,.............
bb,...........
bb,...........
where aa is the indication for master rec and bb for dtl rec
each master rec and recs followig after that but before another master belonfs to one group.while processing the recs if any validation goes wrong i have to put that group of recs(master rec+ detl recs) in a separate file,that is i have to go back and read again the contents and again write to some other file,in utl_file package there is no procedure/function to go back in file,how can we solve this situation.
i am using oracle 8i releae 8.1.7.4.0
Please give your solution

Thanks
C nu

Tom Kyte
May 31, 2003 - 11:53 am UTC

you will be writing a program to procedurally process this file in whatever language you like.

Limit of opened files using utl_file

Reader, May 31, 2003 - 3:06 pm UTC

Tom,
Is there any limit on number of files can be opened for a given session?

Tom Kyte
May 31, 2003 - 4:33 pm UTC

yes, as determined by the operating system (and given that oracle itself has files opened)

How may files can be read at a given session.

Vinod, March 15, 2005 - 4:21 am UTC

Secanrio : WinNT, DB 8.1.6
We are reading files thru the UTL file reader sequentially. But at some point of time ( say after 15 - 16 occurances) the UTL reader is unable to process further files but it pretends in doing so (as this process is mapped to a table with a status column which returns the success flag). There could be more than 25 files to read sequentially at some time. What can be done to over come this sort of error.
Is there any wait/time delay statement that can be put into PL/Sql
Please advice.
Vinod


Tom Kyte
March 15, 2005 - 8:16 am UTC

sorry -- totally insufficient data here.

code doesn't "pretend".

sounds like maybe you are forgetting to close files -- you cannot open any new files -- but your code is perhaps ignoring errors (do you have any exception blocks? comment them all out and see what you see then)

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library