Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
5.06 Mб
Скачать

18.3.6.2 Central error handler

While it is possible to implement separate SERVERERROR triggers in every schema in a database, I recommend creating a single central trigger with an accompanying PL/SQL package to provide the following features.

Centralized error logging

There is only one trigger and package to maintain and keep in Oracle's memory.

Session-long searchable error log

The error log can be accumulated over the course of a session rather than error by error. It can be searched to return details like the number of occurrences, the timestamp of the first and last occurrence, etc. The log can also be purged on demand.

Option to save error log

The error log can be saved to a permanent table in the database if desired.

Viewable current log

The current log of errors is viewable by specific error number and/or date range.

You can find the implementation of one such centralized error-handling package in the error_log.sql file on the O'Reilly site. Once this package is in place, we can create the SERVERERROR trigger as follows:

CREATE OR REPLACE TRIGGER error_log

AFTER SERVERERROR

ON DATABASE

BEGIN

central_error_log.log_error;

END;

Here are some example usages. First, I will generate an error:

SQL> EXEC DBMS_OUTPUT.PUT_LINE(TO_NUMBER('A'));

*

ERROR at line 1:

ORA-06502: PL/SQL: numeric or value error: character to number conversion error

Now I can search for a specific error number and retrieve that information in a record:

DECLARE

v_find_record central_error_log.v_find_record;

BEGIN

central_error_log.find_error(6502,v_find_record);

DBMS_OUTPUT.PUT_LINE('Total Found = ' || v_find_record.total_found);

DBMS_OUTPUT.PUT_LINE('Min Timestamp = ' || v_find_record.min_timestamp);

DBMS_OUTPUT.PUT_LINE('Max Timestamp = ' || v_find_record.max_timestamp);

END;

The output is:

Total Found = 1

Min Timestamp = 04-JAN-02

Max Timestamp = 04-JAN-02

18.3.7 Impact of Invalid Triggers

If database event triggers are in an invalid state, they can cause other actions to fail, as shown here:

Event

If invalid...

AFTER SERVERERROR

All transactions that encounter an Oracle error will be rolled back, and a message detailing the invalid trigger will display.

AFTER LOGON

Only users with the ADMINISTER DATABASE TRIGGER privilege will be able to log on.

BEFORE LOGOFF

Users will see an invalid trigger message when they disconnect from the database.

BEFORE SHUTDOWN

Message stating invalid trigger will display in the database alert log, but shutdown will proceed normally.

AFTER STARTUP

Message stating invalid trigger will display in the database alert log, but startup will proceed normally.

18.4 Instead of Triggers

INSTEAD OF triggers control insert, update, and delete operations on views, not tables. They can be used to make non-updateable views updateable and to override the default behavior of views that are updateable.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]