[Oracle] 如何使用触发器实现IP限制用户登录
海兴,十堰区号,尼坤因宋茜暴打昌珉
下面是一个触发器的例子:
create or replace trigger logon_ip_control
after logon on database
declare
ip string(30);
user string(30);
begin
select sys_context('userenv','session_user') into user from dual;
select sys_context('userenv','ip_address') into ip from dual;
if user='epay_user'
then
if ip not in ('192.168.219.20','192.168.219.22')
then raise_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.%‘)。
下面看几个例子测试一下:
1)从非允许ip地址登陆 (192.168.219.21),连接失败
[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 occurred at recursive sql level 1
ora-20001: user epay_user is not allowed to connect from 192.168.219.21
ora-06512: at line 10
2)从允许ip地址登陆(192.168.219.22),连接成功
[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 edition release 11.2.0.3.0 - 64bit production
with the partitioning, olap, data mining and real application testing options
3)从本地登陆(192.168.219.23)不受ip限制影响,连接成功
[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 edition release 11.2.0.3.0 - 64bit production
with the partitioning, olap, data mining and real application testing options
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
快速向表插入大量数据
当需要对一个非常大的表INSERT的时候,会消耗非常多的资源,因为update表的时候,oracle需要生成 redo log和undo log;此时最...
[阅读全文]
-
-
-
Oracle入门学习五
学习视频: https://www.bilibili.com/video/BV1tJ411r7EC?p=55 数据的完整性:保证插入表格的数据必须正确。...
[阅读全文]
-
Oracle入门学习六
事务:把一组操作看做一个工作单元,要么都执行,要么都不执行。dml操作才有事务,查询没有事务。 开始事务:从上一次的事务结束之后,从第一次dml操作,就...
[阅读全文]
-
-
-
Oracle入门学习一
oracle的安装,用户授权,表格操作,数据类型,ddl表格,dml数据。 下一篇:Oracle入门学习二 学习视频:https://www.bilib...
[阅读全文]
-
Oracle入门学习二
上一篇:Oracle入门学习一 学习视频:https://www.bilibili.com/video/BV1tJ411r7EC?p=15 算术运算符:...
[阅读全文]
网友评论