Here is an example for Oracle. Similar code can be used with other database systems CREATE OR REPLACE TRIGGER acct_change_email ON accounts AFTER UPDATE FOR EACH ROW DECLARE ret_code INTEGER := -1; BEGIN IF :new.acct_balance < 0 THEN -- Insufficient funds. -- Send email notification to the account manager SELECT db_mail.send_mail(email, 'WARNING: Insufficient funds', 'Time: ' || SYSDATE || chr(10) || 'Account: ' || :new.acct_nbr || chr(10) || 'New balance: ' || :new.acct_balance, NULL) INTO ret_code FROM managers WHERE id = :new.mgr_id AND acct = :new.acct_nbr; END;
|