Chapter 3. DBMS_ALERT

Table of Contents

3.1. Overview
3.2. Procedures
3.2.1. REGISTER
3.2.2. REMOVE
3.2.3. REMOVEALL
3.2.4. SET_DEFAULTS
3.2.5. SIGNAL
3.2.6. WAITANY
3.2.7. WAITONE

This chapter briefly introduces the DBMS_ALERT package, and describes how to use the procedures of the package.

3.1. Overview

DBMS_ALERT provides procedures related to Tibero ALERT package for notification and waiting. The package is integrated with a Tibero database. Notification and waiting information is removed when the server restarts.

ALERT is usually used as follows.

  1. Register an alert to wait for. (REGISTER procedure)

  2. Wait for the alert. (WAITANY and WAITONE procedures)

  3. Wake up when the alert is caused by another session because a relevant event occurs. (SIGNAL procedure)

The alert registered in 1. and the alert signal caused in 3. are removed when the server restarts.

The DBMS_ALERT package defines the following constant.

  • MAXWAIT

    MAXWAIT CONSTANT INTEGER :=
            86400000

3.2. Procedures

This section describes the procedures provided by the DBMS_ALERT package, in alphabetical order.

3.2.1. REGISTER

Registers an alert to wait for. A registered alert is valid only in the session that executes this procedure. An alert is registered only once in a session. To use a registered alert in another session, the alert must be registered in the session.

Details about the REGISTER procedure are as follows.

  • Prototype

    DBMS_ALERT.REGISTER
              ( name IN VARCHAR2 ); 
  • Parameter

    ParameterDescription
    nameAlert name to register or wait for.
  • Example

    BEGIN
              DBMS_ALERT.REGISTER('ABC'); END; /

3.2.2. REMOVE

Removes a registered alert. An alert is removed only in the session that executes this procedure. The removal does not have an effect on an alert with the same name in another session. If trying to remove an unregistered alert, an error occurs.

Details about the REMOVE procedure are as follows.

  • Prototype

    DBMS_ALERT.REMOVE
              ( name IN VARCHAR2 ); 
  • Parameter

    ParameterDescription
    nameAlert name to remove.
  • Example

    BEGIN
              DBMS_ALERT.REMOVE('ABC'); END; /

3.2.3. REMOVEALL

Removes all registered alerts. Alerts are removed only in the session that executes this procedure. The removal does not have an effect on alerts with the same names in another session.

Details about the REMOVEALL procedure are as follows.

  • Prototype

    DBMS_ALERT.REMOVEALL
              ( ); 
  • Example

    BEGIN
              DBMS_ALERT.REMOVEALL(); END; /

3.2.4. SET_DEFAULTS

Currently not used.

3.2.5. SIGNAL

Causes an alert to wake up sessions that wait for the alert.

Details about the SIGNAL procedure are as follows.

  • Prototype

    DBMS_ALERT.SIGNAL
              ( name IN VARCHAR2, message IN VARCHAR2 ); 
  • Parameter

    ParameterDescription
    nameAlert name.
    messageUp to 128-byte message that will be sent along with the alert.
  • Example

    BEGIN
              DBMS_ALERT.SIGNAL('ABC', 'DEF'); END; /

3.2.6. WAITANY

Waits for any registered alert. The session that registered the alert wakes up when the alert occurs or timeout expires. The alert is not removed automatically.

Details about the WAITANY procedure are as follows.

  • Prototype

    DBMS_ALERT.WAITANY
              ( name OUT VARCHAR2, message OUT VARCHAR2, status OUT VARCHAR2,
              timeout IN VARCHAR2 ); 
  • Parameter

    ParameterDescription
    nameAlert name that wakes the session up. No value is specified if the session wakes up because of timeout.
    messageMessage that will be sent along with the alert. No value is specified if the session wakes up because of timeout.
    status
    • 1: timeout occurred.

    • 0: alert occurred.

    tiemoutMaximum time to wait for the alert. (Unit: seconds)
  • Example

    set
              serveroutput on declare name varchar(1000); msg varchar(1000);
              status integer; begin dbms_alert.register('ABC');
              dbms_alert.waitany(name, msg, status, 100000);
              dbms_output.put_line(name); dbms_output.put_line(msg);
              dbms_output.put_line(status); END; /

3.2.7. WAITONE

Waits for a specific registered alert. If an unregistered alert is specified, an error occurs. The session that registered the alert wakes up when the alert occurs or timeout expires. The alert is not removed automatically.

Details about the WAITONE procedure are as follows.

  • Prototype

    DBMS_ALERT.WAITONE
              ( name IN VARCHAR2, message OUT VARCHAR2, status OUT VARCHAR2,
              timeout IN VARCHAR2 ); 
  • Parameter

    ParameterDescription
    nameAlert name to wait for.
    messageMessage that will be sent along with the alert. No value is specified if the session wakes up because of timeout.
    status
    • 1: timeout occurred.

    • 0: alert occurred.

    tiemoutMaximum time to wait for the alert. (Unit: seconds)
  • Example

    set
              serveroutput on declare name varchar(1000); msg varchar(1000);
              status integer; begin dbms_alert.register('ABC');
              dbms_alert.waitone('ABC', msg, status, 100000);
              dbms_output.put_line(msg); dbms_output.put_line(status); END;
              /