[摘]Oracle限制某个数据库帐号只能在特定机器上连入数据库

      逛论坛的时候发现一个好脚本,记录下来以备日后有用:

CREATE OR REPLACE TRIGGER sys.trg_work_log
AFTER LOGON ON DATABASE
declare
v_program_name varchar2(200);
v_username varchar2(100);
v_ip varchar2(18);
v_error varchar2(1000);
begin
select username,program,SYS_CONTEXT('USERENV','IP_ADDRESS')   
into v_username,v_program_name,v_ip
from sys.v_$session where AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID');
if (upper(v_username)='TEST') then
  if (UPPER(v_program_name) = 'SQLPLUS.EXE') then
     if (v_ip = ('10.142.244.30')) then
       RAISE_APPLICATION_ERROR(-20001,'You are not allowed to connect to the database,err01');
         
    end if;
  ELSE
     RAISE_APPLICATION_ERROR(-20001,'不能使用sqlplus登陸');
        
  end if;
else
   RAISE_APPLICATION_ERROR(-20001,'You are not allowed to connect to the database');
   
end if;

END ;
/
posted @ 2011-04-22 00:34  killkill  阅读(852)  评论(0编辑  收藏