|Oracle8i Supplied PL/SQL Packages Reference
Release 2 (8.1.6)
Part Number A76936-01
DBMS_ALERT package provides support for the asynchronous notification of database events (alerts). By appropriate use of this package and database triggers, an application can cause itself to be notified whenever values of interest in the database are changed.
For example, suppose a graphics tool is displaying a graph of some data from a database table. The graphics tool can, after reading and graphing the data, wait on a database alert (
WAITONE) covering the data just read. The tool automatically wakes up when the data is changed by any other user. All that is required is that a trigger be placed on the database table, which then performs a signal (
SIGNAL) whenever the trigger is fired.
Alerts are transaction-based. This means that the waiting session does not get alerted until the transaction signalling the alert commits.There can be any number of concurrent signallers of a given alert, and there can be any number of concurrent waiters on a given alert.
A waiting application is blocked in the database and cannot do any other work.
Security on this package can be controlled by granting
EXECUTE on this package to selected users or roles. You might want to write a cover package on top of this one that restricts the alert names used.
EXECUTE privilege on this cover package can then be granted rather than on this package.
The maximum time to wait for an alert (this is essentially forever).
DBMS_ALERT raises the application error -20000 on error conditions. This table shows the messages and the procedures that can raise them.
The application can register for multiple events and can then wait for any of them to occur using the
An application can also supply an optional
timeout parameter to the
WAITANY procedures. A
timeout of 0 returns immediately if there is no pending alert.
The signalling session can optionally pass a message that is received by the waiting session.
Alerts can be signalled more often than the corresponding application wait calls. In such cases, the older alerts are discarded. The application always gets the latest alert (based on transaction commit times).
If the application does not require transaction-based alerts, then the
DBMS_PIPE package may provide a useful alternative.
If the transaction is rolled back after the call to
SIGNAL, then no alert occurs.
It is possible to receive an alert, read the data, and find that no data has changed. This is because the data changed after the prior alert, but before the data was read for that prior alert.
Usually, Oracle is event-driven; this means that there are no polling loops. There are two cases where polling loops can occur:
WAITANYprocedure. If you use the
WAITANYprocedure, and if a signalling session does a signal but does not commit within one second of the signal, then a polling loop is required so that this uncommitted alert does not camouflage other alerts. The polling loop begins at a one second interval and exponentially backs off to 30-second intervals.