2016-06-21 2 views
0

Meine Forderung ist es, eine E-Mail-Benachrichtigung zu senden, wenn ein Gegenstand wie Prozedur oder Tabelle erstellt oder geändert wird in das DatenbankschemaKann ich E-Mail-Benachrichtigung, wenn ein Verfahren (Objekt) erstellt oder geändert wird in Oracle-Datenbank-Schema

+1

Sie möchten gerne ein DDL-Trigger müssen - siehe https: //asktom.oracle.com/pls/asktom/f p = 100: 11: 0 :::? : p11_question_id: 267415465220 – Boneist

+0

Mögliches Duplikat von [Oracle: So protokollieren Sie das Ereignis zum Umbenennen einer Tabelle mit dem DDL-Trigger] (http://stackoverflow.com/questions/32580702/oracle-how-to-log-table-rename-event-using-using- ddl-Trigger) –

Antwort

0

Sie schicken müssen zwei Dinge:

create or replace TRIGGER AUDIT_DDL_TRIGGER AFTER ddl or ALTER OR RENAME ON schema 
DECLARE 
BEGIN 
    send_mail(p_to  => '[email protected]', 
      p_from  => '[email protected]', 
      p_subject => 'DDL!', 
      p_message => 'A DDL or ALTER or RENAME occurred.', 
      p_smtp_host => 'smtp.mycompany.com'); 
END; 
/

Send_mail Funktion ist:

CREATE OR REPLACE PROCEDURE send_mail (p_to  IN VARCHAR2, 
             p_from  IN VARCHAR2, 
             p_message IN VARCHAR2, 
             p_smtp_host IN VARCHAR2, 
             p_smtp_port IN NUMBER DEFAULT 25) 
AS 
    l_mail_conn UTL_SMTP.connection; 
BEGIN 
    l_mail_conn := UTL_SMTP.open_connection(p_smtp_host, p_smtp_port); 
    UTL_SMTP.helo(l_mail_conn, p_smtp_host); 
    UTL_SMTP.mail(l_mail_conn, p_from); 
    UTL_SMTP.rcpt(l_mail_conn, p_to); 
    UTL_SMTP.data(l_mail_conn, p_message || UTL_TCP.crlf || UTL_TCP.crlf); 
    UTL_SMTP.quit(l_mail_conn); 
END; 
/
Verwandte Themen