二、使用触发器
由于sqlnet.ora方式不支持IP段,对于某个IP段的限制,可以使用触发器实现
1、需求:限制IP段 192.168.137登录
2、实现方式:
Oracle@oracle[/oracle/app/10g/network/admin]> sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jun 15 12:25:32 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
sys@ORCL>
sys@ORCL> create or replace trigger chk_ip
2 after logon on scott.schema
3 declare
4 ipaddr VARCHAR2(30);
5 begin
6 select sys_context('userenv', 'ip_address') into ipaddr from dual;
7 if ipaddr like ('192.168.137.%') then
8 raise_application_error('-20001', 'you can not logon by scott');
9 end if;
10 end chk_ip;
11 /
Trigger created.
sys@ORCL>
在192.168.137.1上登录,显示:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: you can not logon by scott
ORA-06512: at line 6
显然使用触发器会带来更多便利