13.6. Writing to a File

When you open a file in write-only mode (PLVfile.c_write) or append mode (PLVfile.c_append), you usually then want to write or put a line into that file. To do this, you will call the PLVfile.put_line procedure, whose header is shown below:

PROCEDURE put_line
   (file_in IN UTL_FILE.FILE_TYPE, line_in IN VARCHAR2);

Notice that you must provide a file handle to put a line in a file. You must, therefore, have already opened the file using one of the function versions of fopen.

13.6.1. Appending a Line

The append_line procedure offers a quick way to add a line on to the end of a file. Its header is:

PROCEDURE append_line (file_in IN VARCHAR2, line_in IN VARCHAR2);

You provide the file and the line you want appended on the end of the file. PLVfile automatically opens the file in append mode, writes the line using put_line, and then closes the file.

Get Advanced Oracle PL/SQL Programming with Packages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.