Oracle8i Supplied PL/SQL Packages Reference Release 2 (8.1.6) Part Number A76936-01 |
|
UTL_FILE , 2 of 2
Subprogram | Description |
---|---|
|
Opens a file for input or output with the default line size. |
|
Determines if a file handle refers to an open file. |
|
Closes a file. |
|
Closes all open file handles. |
|
Reads a line of text from an open file. |
|
Writes a line to a file. This does not append a line terminator. |
|
Writes one or more OS-specific line terminators to a file. |
|
Writes a line to a file. This appends an OS-specific line terminator. |
|
A |
|
Physically writes all pending output to a file. |
FOPEN Function |
Opens a file with the maximum line size specified. |
This function opens a file for input or output. The file location must be an accessible directory, as defined in the instance's initialization parameter UTL_FILE_DIR
. The complete directory path must already exist; it is not created by FOPEN
.
FOPEN
returns a file handle, which must be used in all subsequent I/O operations on the file.
This version of FOPEN
does not take a parameter for the maximum line size. Thus, the default (which is 1023 on most systems) is used. To specify a different maximum line size, use the other, overloaded version of "FOPEN Function".
You can have a maximum of 50 files open simultaneously.
UTL_FILE.FOPEN ( location IN VARCHAR2, filename IN VARCHAR2, open_mode IN VARCHAR2) RETURN UTL_FILE.FILE_TYPE;
FOPEN
returns a file handle, which must be passed to all subsequent procedures that operate on that file. The specific contents of the file handle are private to the UTL_FILE
package, and individual components should not be referenced or changed by the UTL_FILE
user.
INVALID_PATH
INVALID_MODE
INVALID_OPERATION
This function tests a file handle to see if it identifies an open file. IS_OPEN
reports only whether a file handle represents a file that has been opened, but not yet closed. It does not guarantee that there will be no operating system errors when you attempt to use the file handle.
UTL_FILE.IS_OPEN ( file IN FILE_TYPE) RETURN BOOLEAN;
Parameter | Description |
---|---|
file |
Active file handle returned by an |
TRUE
or FALSE
None.
This procedure closes an open file identified by a file handle. If there is buffered data yet to be written when FCLOSE
runs, then you may receive a WRITE_ERROR
exception when closing a file.
UTL_FILE.FCLOSE ( file IN OUT FILE_TYPE);
Parameter | Description |
---|---|
file |
Active file handle returned by an |
WRITE_ERROR
INVALID_FILEHANDLE
This procedure closes all open file handles for the session. This should be used as an emergency cleanup procedure, for example, when a PL/SQL program exits on an exception.
UTL_FILE.FCLOSE_ALL;
None.
WRITE_ERROR
This procedure reads a line of text from the open file identified by the file handle and places the text in the output buffer parameter. Text is read up to but not including the line terminator, or up to the end of the file.
If the line does not fit in the buffer, then a VALUE_ERROR
exception is raised. If no text was read due to "end of file," then the NO_DATA_FOUND
exception is raised.
Because the line terminator character is not read into the buffer, reading blank lines returns empty strings.
The maximum size of an input record is 1023 bytes, unless you specify a larger size in the overloaded version of FOPEN
.
UTL_FILE.GET_LINE ( file IN FILE_TYPE, buffer OUT VARCHAR2);
INVALID_FILEHANDLE
INVALID_OPERATION
READ_ERROR
NO_DATA_FOUND
VALUE_ERROR
PUT
writes the text string stored in the buffer parameter to the open file identified by the file handle. The file must be open for write operations. No line terminator is appended by PUT
; use NEW_LINE
to terminate the line or use PUT_LINE
to write a complete line with a line terminator.
The maximum size of an input record is 1023 bytes, unless you specify a larger size in the overloaded version of FOPEN
.
UTL_FILE.PUT ( file IN FILE_TYPE, buffer IN VARCHAR2);
INVALID_FILEHANDLE
INVALID_OPERATION
WRITE_ERROR
This procedure writes one or more line terminators to the file identified by the input file handle. This procedure is separate from PUT
because the line terminator is a platform-specific character or sequence of characters.
UTL_FILE.NEW_LINE ( file IN FILE_TYPE, lines IN NATURAL := 1);
Parameters | Description |
---|---|
file |
Active file handle returned by an |
lines |
Number of line terminators to be written to the file. |
INVALID_FILEHANDLE
INVALID_OPERATION
WRITE_ERROR
This procedure writes the text string stored in the buffer parameter to the open file identified by the file handle. The file must be open for write operations. PUT_LINE
terminates the line with the platform-specific line terminator character or characters.
The maximum size for an output record is 1023 bytes, unless you specify a larger value using the overloaded version of FOPEN
.
UTL_FILE.PUT_LINE ( file IN FILE_TYPE, buffer IN VARCHAR2);
Parameters | Description |
---|---|
file |
Active file handle returned by an |
buffer |
Text buffer that contains the lines to be written to the file. |
INVALID_FILEHANDLE
INVALID_OPERATION
WRITE_ERROR
This procedure is a formatted PUT
procedure. It works like a limited printf
(). The format string can contain any text, but the character sequences '%s' and '\n' have special meaning.
%s |
Substitute this sequence with the string value of the next argument in the argument list. |
\n |
Substitute with the appropriate platform-specific line terminator. |
UTL_FILE.PUTF ( file IN FILE_TYPE, format IN VARCHAR2, [arg1 IN VARCHAR2 DEFAULT NULL, . . . arg5 IN VARCHAR2 DEFAULT NULL]);
The following example writes the lines:
Hello, world! I come from Zork with greetings for all earthlings. my_world varchar2(4) := 'Zork'; ... PUTF(my_handle, 'Hello, world!\nI come from %s with %s.\n', my_world, 'greetings for all earthlings');
If there are more %s
formatters in the format parameter than there are arguments, then an empty string is substituted for each %s
for which there is no matching argument.
INVALID_FILEHANDLE
INVALID_OPERATION
WRITE_ERROR
FFLUSH
physically writes pending data to the file identified by the file handle. Normally, data being written to a file is buffered. The FFLUSH
procedure forces the buffered data to be written to the file. The data must be terminated with a newline character.
Flushing is useful when the file must be read while still open. For example, debugging messages can be flushed to the file so that they can be read immediately.
UTL_FILE.FFLUSH ( file IN FILE_TYPE); invalid_maxlinesize EXCEPTION;
Parameters | Description |
---|---|
file |
Active file handle returned by an |
INVALID_FILEHANDLE
INVALID_OPERATION
WRITE_ERROR
This function opens a file. You can have a maximum of 50 files open simultaneously.
Note:
This version of |
UTL_FILE.FOPEN ( location IN VARCHAR2, filename IN VARCHAR2, open_mode IN VARCHAR2, max_linesize IN BINARY_INTEGER) RETURN file_type;
Return | Description |
---|---|
file_type |
Handle to open file. |
INVALID_PATH
: File location or name was invalid.INVALID_MODE
: Theopen_mode
string was invalid.INVALID_OPERATION
: File could not be opened as requested.INVALID_MAXLINESIZE
: Specifiedmax_linesize
is too large or too small.
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|