xifenfei 发表于 2018-7-12 12:19:47

触发器禁止exp导出数据

--触发器禁止exp   dba权限用户不能被控制
create or replace
TRIGGER DISABLE_EXP
AFTER logon ON DATABASE
DECLARE
mtSession v$session%ROWTYPE;
CURSOR cSession(iiQuerySid IN NUMBER) IS
   SELECT * FROM v$session where USERNAME is not null
    and nvl(osuser,'x') <> 'SYSTEM'   and type <> 'BACKGROUND' and upper(module) like 'EXP%' and audsid = iiQuerySid;
V_SQL VARCHAR2(100);
BEGIN
OPEN cSession(userenv('SESSIONID'));
FETCH cSession INTO mtSession;
IF cSession%FOUND THEN
V_SQL:=' alter system kill session '||''''||mtSession.Sid||','||mtSession.Serial#||'''';
EXECUTE IMMEDIATE V_SQL;
END IF;
CLOSE cSession;
EXCEPTION
WHEN OTHERS THEN
    RAISE;
END;


--10G及其以上版本,9i中无sys_context('USERENV', 'MODULE')
CREATE OR REPLACE TRIGGER DISABLE_EXP
AFTER LOGON ON DATABASE
DECLARE
my_forced_exception EXCEPTION;
PRAGMA EXCEPTION_INIT(MY_FORCED_EXCEPTION, -20101);
BEGIN
    IF (UPPER(sys_context('USERENV', 'MODULE')) LIKE 'EXP%')
   THEN
      RAISE my_forced_exception;
   END IF;
EXCEPTION
WHEN my_forced_exception THEN
    RAISE_APPLICATION_ERROR(-20101,
                            'USER ' ||
                            sys_context('USERENV', 'SESSION_USER') || ' ' ||
                            'MODULE ' ||
                            UPPER(sys_context('USERENV', 'MODULE')) || ' ' || ' Ban export data !');
WHEN OTHERS THEN
    null;
END;
/

页: [1]
查看完整版本: 触发器禁止exp导出数据