Skip to content
Advertisement

how to get a popup when someone has connected to particular database

Is there any way i can write a script to get a popup as an email that some x user has connected to a particular database

Scenario: there was an “X” database and if some “ABC” user has logged into that database by using some account user id and password , an email should be triggered to some contacts : saying — that particular user has connected to that database.

We are currently using Toad / Sql Developer as a third party tools to connect to oracle database.

Is there any way i can achieve this by righting a sql procedure or shell script or any other way.

Advertisement

Answer

One option is to create an AFTER LOGON trigger, e.g.

CREATE OR REPLACE TRIGGER trg_user_connected
   AFTER LOGON
   ON DATABASE
DECLARE
  l_global_name varchar2(30);
BEGIN
   SELECT global_name
     INTO l_global_name
     FROM global_name;

   UTL_MAIL.send (sender      => 'noreply@orcl',
                  recipients  => 'avinash@gmail.com',
                  cc          => NULL,
                  bcc         => NULL,
                  mime_type   => NULL,
                  subject     => 'Logged right now into ' || l_global_name,
                  MESSAGE     => USER);
END;
/

You’ll probably want to restrict it, somehow (otherwise your inbox will explode :)).

[EDIT: dropping an object]

CREATE OR REPLACE TRIGGER trg_bd
   AFTER DROP
   ON SCHEMA
DECLARE
   oper  VARCHAR2 (100);
BEGIN
   SELECT ora_sysevent INTO oper FROM DUAL;

   IF oper = 'DROP'
   THEN
      utl_mail.send ...
   END IF;
END;
/
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement