Use the system package DBMS_ALERT to monitor the table

Source: Internet
Author: User


Use the system package DBMS_ALERT to monitor the table DBMS_ALERT and support asynchronous database event capturing. www.2cto.com is now testing the changes in the captured table. The test table is emp. because it is asynchronous, we need to open two SQLPLUS windows (two sessions) here to write the stored procedure in the first session as follows: (Note that the SCOTT user permission should be given first, grant execute on dbms_alert to scott) [SQL] declare v_n varchar2 (30); v_m varchar2 (100); v_ I integer; begin alias; dbms_alert.register ('emp_table_alert '); dbms_alert.waitany (v_n, v_m, v_ I); if l_ I = 0 then dbms_output.put_line ('[name:]' | Rochelle N); dbms_output.put_line ('[msg:]' | l_m); end if; dbms_alert.removeall; end;/after the stored procedure is executed, the session will be waiting... We re-open a new sqlplus and create a trigger as follows: [SQL] create or replace trigger emtring after insert or update or delete on emp begin dbms_alert.signal ('EMP _ table_alert ', to_char (sysdate, 'yyyymmdd') | ': table emp is changed'); end; in which dbms_alert.signal is used to send alerts. In this session, make some changes, for example, insert [SQL] insert into emp (empno, ename) values (1234, 'w001'); commit; Be sure to commit; Because DBMS_ALERT is based on transaction processing. once commit is enabled, the wait state of the session in the first SQLPLUS will end. The output result is as follows: [SQL] 10:18:18 SCOTT @ orcl>/[name:] EMP_TABLE_ALERT [msg:] 20121212: table emp is changed. This package is generally used in development. Various alarms in the database are captured in the application for processing.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.