File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Oracle/OAS and the fly likes Read File in PL/SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Read File in PL/SQL" Watch "Read File in PL/SQL" New topic

Read File in PL/SQL

Jackie Wang
Ranch Hand

Joined: Apr 18, 2002
Posts: 315
I am using oracle 8i,
I am trying to read the first 10 character of the first line
I have define

i changed from
UTL_FILE.GET_LINE(br, sLine, 10); - the first 10 characters of the file?
and i got this error:
PLS-00306: wrong number or types of arguments in call to 'GET_LINE'

if I changed to
br := UTL_FILE.FOPEN_NCHAR (strFilePath, strFileName, 'r');
PL/SQL: Statement ignored
PLS-00302: component 'FOPEN_NCHAR' must be declared
PL/SQL: Statement ignored
PLS-00302: component 'GET_LINE_NCHAR' must be declared

are those function only in 9i?
appreciated your help.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Programs added with version 9i

I got this Revealnet's Knowledge base.
So it looks like those are for 9i. Sorry.
You just want the first ten characters. Here's a way.
Assumption #1. The first ten characters are always on the first line.
use GET_LINE, then in you next statement assign the first ten characters to another variable.
If you have

Something like that.
Or if the first ten characters are not always on the first line then you need to loop and continue reading lines until the length of trim(firstTen) = 10. Also you need to have an IF to make sure that the strBuffer is not more than ten and act accordingly in your assignment of firstTen, such that you don't try to add characters that make it go over it's 10 character limit.
Good Luck and I hope that helps.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
srikanth sankurthi

Joined: Oct 09, 2012
Posts: 9
can you post your total code.
chris webster

Joined: Mar 01, 2009
Posts: 2288

srikanth sankurthi wrote:can you post your total code.

The original post is from about 10 years ago, and refers to Oracle 8i, so the code may not be all that helpful these days!

The usual way to read file data in PL/SQL is with the UTL_FILE package, which is well documented on the Oracle website as well as via various examples on other sites. If you have a specific question, you can post it here or on the Oracle Technet forums.

No more Blub for me, thank you, Vicar.
I agree. Here's the link:
subject: Read File in PL/SQL
jQuery in Action, 3rd edition