FOPEN

2023-10-24 09:23:03  Updated

The FOPEN function opens a file based on user-specified information. The system allows you to open up to 50 files at a time.

Syntax

UTL_FILE.FOPEN (
   location          IN VARCHAR2,
   filename         IN VARCHAR2,
   open_mode    IN VARCHAR2,
   max_linesize   IN BINARY_INTEGER DEFAULT 1024)
  RETURN FILE_TYPE;

Parameters

Parameter Description
location The path of the file to open.
filename The name of the file to open. The file name cannot contain forward slashes (/).
open_mode The mode in which the file is opened. Valid values:
  • r: reads text.
  • w: writes text.
  • a: appends text.
  • rb: reads bytes.
  • wb: writes bytes.
  • ab: appends bytes.
If you set open_mode to a or ab when you attempt to open a file but the file does not exist, the file is created in write mode.
max_linesize The maximum number of bytes per line in the file, including line breaks. Value range: [1,32767]. The default value is 1,024 bytes.

Return values

FOPEN returns FILE_TYPE, which indicates the file handle. The file handle must be passed to all subsequent operations on the file. The content of the file handle is private to the UTL_FILE package and therefore cannot be referenced or modified.

Exceptions

  • INVALID_MAXILINESIZE

  • INVALID_MODE

  • INVALID_OPERATION

  • INVALID_PATH

  • INVALID_FILENAME

Usage notes

The file location and file name must be passed to the FOPEN function as quoted strings. This way, the function can check the file location based on the list of accessible directories specified in the ALL_DIRECTORIES view.

When more than 50 files are opened at a time, the INVALID_OPERATION exception is thrown.

Contact Us