WAITANY procedure - Wait for any registered alerts

The WAITANY procedure waits for any registered alerts to occur.

Syntax

Read syntax diagramSkip visual syntax diagramDBMS_ALERT.WAITANY (name,message, status,timeout)

Procedure parameters

name
An output argument of type VARCHAR(128) that contains the name of the alert.
message
An output argument of type VARCHAR(32672) that contains the message sent by the SIGNAL procedure.
status
An output argument of type INTEGER that contains the status code returned by the procedure. The following values are possible
0
An alert occurred.
1
A timeout occurred.
timeout
An input argument of type INTEGER that specifies the amount of time in seconds to wait for an alert.

Authorization

EXECUTE privilege on the DBMS_ALERT module.

Examples

From one connection, run a CLP script called waitany.clp to receive any registered alerts.

waitany.clp:

SET SERVEROUTPUT ON@

CREATE PROCEDURE proc1()
BEGIN
  DECLARE v_name    VARCHAR(30);
  DECLARE v_msg     VARCHAR(80);
  DECLARE v_status  INTEGER;
  DECLARE v_timeout INTEGER DEFAULT 20;
  CALL DBMS_ALERT.REGISTER('alert_test');
  CALL DBMS_ALERT.REGISTER('any_alert');
  CALL DBMS_OUTPUT.PUT_LINE('Registered for alert alert_test and any_alert'); 
  CALL DBMS_OUTPUT.PUT_LINE('Waiting for signal...');
  CALL DBMS_ALERT.WAITANY(v_name , v_msg , v_status , v_timeout);
  CALL DBMS_OUTPUT.PUT_LINE('Alert name : ' || v_name);
  CALL DBMS_OUTPUT.PUT_LINE('Alert msg : ' || v_msg);
  CALL DBMS_OUTPUT.PUT_LINE('Alert status : ' || v_status);
  CALL DBMS_OUTPUT.PUT_LINE('Alert timeout: ' || v_timeout || ' seconds');
  CALL DBMS_ALERT.REMOVEALL;
END@

call proc1@

From another connection, run a script called signal.clp to issue a signal for an alert named any_alert.

signal.clp:

SET SERVEROUTPUT ON@

CREATE PROCEDURE proc2
  BEGIN
  DECLARE v_name VARCHAR(30) DEFAULT 'any_alert';
  CALL DBMS_ALERT.SIGNAL(v_name,'This is the message from ' || v_name);
  CALL DBMS_OUTPUT.PUT_LINE('Issued alert for ' || v_name);
END@

CALL proc2@

The script signal.clp results in the following output:

Issued alert for any_alert

The script waitany.clp results in the following output:

Registered for alert alert_test and any_alert
Waiting for signal...
Alert name : any_alert
Alert msg : This is the message from any_alert
Alert status : 0
Alert timeout: 20 seconds

Usage notes

If no alerts are registered when the WAITANY procedure is called, the procedure returns SQL0443N.