create or replace trigger
LOGon_ip_control
after logon on database
declare
&nbs
p; ip STRING(30);
user STRING(30);
be
ginSELECT
Sys_CONTEXT('USER
env','SESSION_USER') into user
From dual;
SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') into ip f
rom dual;
if user='EPAY_USER'
THEN
IF ip not in ('192.168.219.20','192.168.219.22')
THEN r
aise_application_error(-20001,'User '||user||' is not
Allowed to connect from '||ip);
END IF;
END IF;
end;
/
该触发器对用户EPAY_USER进行了IP限制(只允许'192.168.219.20','192.168.219.22',如果需要设置IP段,用%或?代替即可,如'192.168.219.%‘)。
[
oracle@lxdb2 ~]$
SQLplus epay_user@
PRi
SQL*Plus: Release 11.2.0.3.0 Production on Wed Jul 3 19:23:48 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-00604: error occur
red at recursive SQL level 1
ORA-20001: User EPAY_USER is not allowed to connect from 192.168.219.21
ORA-06
512: at line 10
[oracle@lxdb1 ~]$ sqlplus epay_user
SQL*Plus: Release 11.2.0.3.0 Production on Wed Jul 3 11:24:25 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g
Enterprise Ed
ITion Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application
testing options