About Oracle utl_file Package
This easy
writing to the alert log is accomplished by
using Oracle’s utl_file package. The
Oracle utl_file package allows Oracle SQL and
PL/SQL to read and write directly from flat
files on the server.
Writing custom messages to the Oracle alert
log requires the following steps:
1 - Locate the background dump directory
(the location of the alert log).
2 - Set the utl_file_dir initialization
parameter.
3 - Execute utl_file.fopen to open the file
for write access.
4 - Use dbms_output.put_line to write the
custom message to the alert log.
5 - Execute utl_file.fclose to close the
file
--
******************************************************
-- Gather the location of the alert log
directory
--
******************************************************
select
name into :alert_loc
from
v$parameter
where
name = ‘background_dump_destination’;
--
******************************************************
-- Set the utl_file_dir
-- (prior to Oracle9i, you must bounce the
database)
--
******************************************************
alter system set utl_file_dir = ‘:alert_log’);
--
******************************************************
-- Open the alert log file for write access
--
******************************************************
utl_file.fopen(':alert_loc',’alertprod.log’,'W');
--
******************************************************
-- Write the custom message to the alert log
file
--
******************************************************
dbms_output.put_line('invalid_application_error');
--
******************************************************
-- Close the alert log file
--
******************************************************
utl_file.fclose(':alert_loc');
Oracle lets a database program write to flat
files using the utl_file utility
FILE
SYSTEM 3
DESCRIPTION
(Directory of files created using the
utl_file package)
The user interaction directory is placed
here. The files created using the package
utl_file are generated in this directory.
Since users will frequently read and write
files in this directory, this should be
separated. The directory should be owned by
Oracle with permissions set for read, write
and execute for everyone.
Please note then in Oracle 9i, the utl_file
package does not need this parameter to be
set in init.ora to manipulate a file. The
DIRECTORY object can be dynamically created
and used as the directory. Therefore, the
days of this filesystem could be numbered.
Also see these related notes on Oracle utl_file:
Incorrect utl_file permission umask tips
|
|