Skip Headers
Oracle® OLAP DML Reference
10g Release 2 (10.2)

Part Number B14346-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

FILEGET

The FILEGET function returns text from a non-binary file that has been opened for reading. When FILEGET reaches the end of the file, it returns NA. All text read with FILEGET is translated into the database character set. FILEGET cannot read data that cannot be represented in the database character set.

Return Value

TEXT

Syntax

FILEGET(fileunit [LENGTH int-expression])

Arguments

fileunit

AnINTEGER value that was assigned to a file opened for reading in a previous call to the FILEOPEN function.

LENGTH int-expression

An INTEGER expression specifying the number of bytes FILEGET returns from the file. When an end-of-line character is reached in the input file, FILEGET simply starts a new line in the result it is constructing. When LENGTH is omitted, FILEGET reads one line or record regardless of how many bytes it contains.

Notes

Difference Between Number of Bytes Read and Number of Bytes Returned

The value specified by LENGTH refers to the number of bytes that the FILEGET function returns, not to the number of bytes that it reads. In some cases, these values may differ. For example, when the file being read contains a tab character, the number of bytes returned by FILEGET includes the bytes for tab expansion (if any); consequently, the number of bytes returned by FILEGET could be larger than the number of bytes read by FILEGET.

Examples

Example 12-15 Program for Reading a File

Suppose you have a program called readfile that takes a file name as its argument. It opens the file, reads the lines of the file, adds them to a multiline text variable named wholetext, then closes it. readfile uses local variables to store the fileunit number and each line of the file as it is read.

DEFINE wholetext VARIABLE TEXT
LD Multiline text variable
DEFINE readfile PROGRAM
LD Program to store data from a file in a multiline text variable
PROGRAM
VARIABLE fil.unit INTEGER  "Local Var To Store File Unit
VARIABLE fil.text TEXT     "Local Var To Store Single Lines
FIL.UNIT = FILEOPEN(ARG(1) READ)
FIL.TEXT = FILEGET(fil.unit)        "Read The First Line
WHILE fil.text NE NA                "Test For End-of-file
  DO
  wholetext = JOINLINES(wholetext, fil.text)
  fil.text = FILEGET(fil.unit)      "Read The Next Line
  DOEND
FILECLOSE fil.unit
END