Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read File in PL/SQL

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
srikanth sankurthi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post your total code.
 
chris webster
Bartender
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic