Oracle9i OLAP Services Developer's Guide to the OLAP DML
Release 1 (9.0.1)

Part Number A86720-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

Reading Data from Files, 3 of 9


Reading Files

Basic steps: Reading from files

While reading from a file, you can format the data from each field individually, and you can use Express functions to process the information before assigning it to an OLAP DML object. Reading a file generally involves the following steps.

  1. Open the file you want to read.

  2. Read data from the file one record or line at a time.

  3. Process the data and assign it to one or more Express objects.

  4. Close the file.

Methods for reading a file

The FILEREAD and FILEVIEW commands have the same attributes and can do the same processing on your data. However, they differ in important ways:

Consequently, there are two basic methods for reading a file.

Method 

Command 

Description 

Use 

FILEREAD 

Processes all records in a file automatically. 

Use when all records in the file are the same. 

FILENEXT and FILEVIEW 

Reads and processes one record at a time from the file. 

Use when there is more than one type of record in a file. 

Creating a program to read data

The following table shows, for each method, the commands you need to open and close the input file, to read the file, and to handle errors that might occur.

Program Section 

Method 1(FILEREAD) 

Method 2(FILENEXT and FILEVIEW) 

Initialization 

variable funit integer
trap on error
 
variable funit integer
trap on error
 

Body 

funit = fileopen(-
   'datafile' read)
fileread funit 
   .
   .
   .
fileclose funit
 
funit = fileopen(-
   'datafile' read)
while filenext(funit)
   do
   fileview funit . . .
   doend
fileclose funit
 

Normal Exit 

return
 
return
 

Abnormal Exit 

error:
if funit ne na
then fileclose funit
 
error:
if funit ne na
then fileclose funit
 

Note: The error handling in the abnormal exit section of the programs closes the file only when the file is open. The FILEOPEN function signals an error when for any reason the system can not open the file. The program tries to close the file after the ERROR label only when FUNIT holds a valid file unit number. You can add additional commands to the error handling section as well. These sections of the program are the same for both methods.


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback