my dog learned polymorphism*
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
Author

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
br UTL_FILE.FILE_TYPE;

i changed from
UTL_FILE.GET_LINE(br, sLine);
to
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'

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

are those function only in 9i?
appreciated your help.
=)
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6


Programs added with version 9i
FOPEN
FOPEN
FOPEN_NCHAR
FOPEN_NCHAR
GET_LINE_NCHAR
PUT_NCHAR
PUT_LINE_NCHAR
PUTF_NCHAR

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.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
srikanth sankurthi
Greenhorn

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

Joined: Mar 01, 2009
Posts: 1649
    
  14

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: http://aspose.com/file-tools
 
subject: Read File in PL/SQL