oracle+禁用ddl,Oracle使用触发器禁止远程DDL操作

SQL> grant select on v_$session to zhongwc;

Grant succeeded.

SQL> grant execute on dbms_system to zhongwc;

Grant succeeded.

SQL> @ddl_trigger

Trigger created.

SQL> !cat ddl_trigger.sql

create or replace trigger ddl_trigger

before ddl on zhongwc.schema

declare

n number;

str_stmt varchar2(4000);

sql_text ora_name_list_t;

l_trace number;

str_session v$session%rowtype;

begin

select count(*)

into l_trace

from dual

where utl_inaddr.get_host_address is not null

and sys_context('userenv', 'ip_address') is not null

and sys_context('userenv', 'ip_address') <>

utl_inaddr.get_host_address;

if l_trace > 0 then

n := ora_sql_txt(sql_text);

for i in 1 .. n loop

str_stmt := substr(str_stmt || sql_text(i), 1, 3000);

end loop;

select *

into str_session

from v$session

where audsid = userenv('sessionid');

sys.dbms_system.ksdwrt(2,

to_char(sysdate, 'yyyymmdd hh24:mi:ss') ||

'ORA-20001 user: ' || user || ' program: ' ||

str_session.program || ' IP: ' ||

sys_context('userenv', 'ip_address') ||

' object: ' || ora_dict_obj_name || ' DDL: ' ||

str_stmt);

raise_application_error(-20001, 'DDL is deny from remote connection.');

end if;

end;

/

remote

C:\>sqlplus zhongwc@single

SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 1月 15 16:54:01 2013

Copyright (c) 1982, 2005, Oracle. All rights reserved.

输入口令:

连接到:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> truncate table t_test;

truncate table t_test

*

第 1 行出现错误:

ORA-00604: 递归 SQL 级别 1 出现错误

ORA-20001: DDL is deny from remote connection.

ORA-06512: 在 line 34

SQL> drop table t_test;

drop table t_test

*

第 1 行出现错误:

ORA-00604: 递归 SQL 级别 1 出现错误

ORA-20001: DDL is deny from remote connection.

ORA-06512: 在 line 34

SQL> create table t_test002 as select * from t_test;

create table t_test002 as select * from t_test

*

第 1 行出现错误:

ORA-00604: 递归 SQL 级别 1 出现错误

ORA-20001: DDL is deny from remote connection.

ORA-06512: 在 line 34

local

[oracle@zhongwc ~]$ sqlplus zhongwc@zwc

SQL*Plus: Release 11.2.0.3.0 Production on Tue Jan 15 16:58:49 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

SQL> select tname from tab;

TNAME

------------------------------

T_TEST

SQL> create table t_test002 as select * from t_test;

Table created.

SQL> select tname from tab;

TNAME

------------------------------

T_TEST

T_TEST002

收录 eygle DBA 手记4

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值