查看: 9585|回复: 12

能否读对TRUNCATE/DROP/ALTER TABLE 建立触发器

[复制链接]
论坛徽章:
0
跳转到指定楼层
1#
发表于 2007-5-22 15:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
能否读对TRUNCATE/DROP/ALTER TABLE 建立触发器
论坛徽章:
64
会员2007贡献徽章
日期:2007-09-26 18:42:10NBA常规赛纪念章
日期:2008-04-18 19:48:16欧洲冠军杯纪念徽章
日期:2008-05-23 14:31:342009新春纪念徽章
日期:2009-01-04 14:52:28NBA常规赛纪念章
日期:2009-04-16 14:28:42NBA季后赛纪念徽章
日期:2009-06-16 11:28:172010新春纪念徽章
日期:2010-01-04 08:33:08
2#
发表于 2007-5-22 15:42 | 只看该作者
对ddl的触发器

使用道具 举报

回复
论坛徽章:
0
3#
 楼主| 发表于 2007-5-22 16:08 | 只看该作者
最初由 cjf107 发布
[B]对ddl的触发器 [/B]

怎么写呢?

使用道具 举报

回复
论坛徽章:
0
4#
 楼主| 发表于 2007-5-22 19:08 | 只看该作者
up

使用道具 举报

回复
论坛徽章:
16
ITPUB元老
日期:2006-08-12 12:42:51授权会员
日期:2006-08-12 12:36:09数据库板块每日发贴之星
日期:2006-11-19 01:03:11数据库板块每日发贴之星
日期:2007-04-23 01:05:28会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44BLOG每日发帖之星
日期:2008-06-29 01:02:22
5#
发表于 2007-5-22 21:45 | 只看该作者
DDL triggers can be associated with the database or with a schema. Their attributes include the system event, the type of schema object, and its name. They can specify simple conditions on the type and name of the schema object, as well as functions like USERID and USERNAME. DDL triggers include the following types of triggers:

BEFORE CREATE and AFTER CREATE triggers fire when a schema object is created in the database or schema.

BEFORE ALTER and AFTER ALTER triggers fire when a schema object is altered in the database or schema.

BEFORE DROP and AFTER DROP triggers fire when a schema object is dropped from the database or schema.

使用道具 举报

回复
论坛徽章:
16
ITPUB元老
日期:2006-08-12 12:42:51授权会员
日期:2006-08-12 12:36:09数据库板块每日发贴之星
日期:2006-11-19 01:03:11数据库板块每日发贴之星
日期:2007-04-23 01:05:28会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44BLOG每日发帖之星
日期:2008-06-29 01:02:22
6#
发表于 2007-5-22 21:56 | 只看该作者
SQL> create or replace trigger ddl_deny
  2  before alter or drop or truncate on database
  3  declare
  4    l_errmsg varchar2(100):= 'You have no permission to this operation';
  5  begin
  6    if ora_sysevent = '' then
  7       raise_application_error(-20001, ora_dict_obj_owner || '.' || ora_dict_obj_name || ' ' || l_errmsg);
  8    elsif ora_sysevent = 'ALTER' then
  9      raise_application_error(-20001, ora_dict_obj_owner || '.' || ora_dict_obj_name || ' ' || l_errmsg);
10    elsif ora_sysevent = 'DROP' then
11      raise_application_error(-20001, ora_dict_obj_owner || '.' || ora_dict_obj_name || ' ' || l_errmsg);
12    elsif ora_sysevent = 'TRUNCATE' then
13      raise_application_error(-20001, ora_dict_obj_owner || '.' || ora_dict_obj_name || ' ' || l_errmsg);
14    end if;
15  
16  exception
17    when no_data_found then
18      null;
19  end;
20  /

Trigger created.

SQL> create table t
  2  as
  3  select * from dba_objects;

Table created.

SQL> truncate table t;
truncate table t
               *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: SYSTEM.T You have no permission to this operation
ORA-06512: at line 11

使用道具 举报

回复
论坛徽章:
0
7#
 楼主| 发表于 2007-5-23 09:10 | 只看该作者
谢谢,我要对某张表truncatre/DROP/ALTER的时候,才触发

使用道具 举报

回复
论坛徽章:
20
授权会员
日期:2005-11-02 13:35:57ITPUB8周年纪念徽章
日期:2009-09-27 10:21:22祖国60周年纪念徽章
日期:2009-10-09 08:28:00生肖徽章2007版:兔
日期:2009-11-13 10:54:06生肖徽章2007版:蛇
日期:2009-11-28 18:44:592010新春纪念徽章
日期:2010-01-04 08:33:082010新春纪念徽章
日期:2010-03-01 11:06:292010年世界杯参赛球队:瑞士
日期:2010-04-03 20:50:32ITPUB9周年纪念徽章
日期:2010-10-08 09:31:212009日食纪念
日期:2009-07-22 09:30:00
8#
发表于 2007-5-23 11:33 | 只看该作者
那就要在DDL触发器中判断,你的操作是对哪个对象的。
Name
Description

ORA_CLIENT_IP_ADDRESS
Returns the IP address of the client.

ORA_DATABASE_NAME
Returns the name of the database.

ORA_DES_ENCRYPTED_PASSWORD
Returns the DES-encrypted password of the current user.

ORA_DICT_OBJ_NAME
Returns the name of the database object affected by the firing DDL.

ORA_DICT_OBJ_NAME_LIST
Returns the count of objects affected. It also returns a complete list of objects affected in the NAME_LIST parameter, which is a collection of type DBMS_STANDARD.ORA_NAME_LIST_T.

ORA_DICT_OBJ_OWNER
Returns the owner of the database object affected by the firing DDL.

ORA_DICT_OBJ_OWNER_LIST
Returns the count of objects affected. It also returns a complete list of object owners affected in the NAME_LIST parameter, which is a collection of type DBMS_STANDARD.ORA_NAME_LIST_T.

ORA_DICT_OBJ_TYPE
Returns the type of database object affected by the firing DDL (e.g., TABLE or INDEX).

ORA_GRANTEE
Returns the count of grantees. The USER_LIST argument contains the full list of grantees, which is a collection of type DBMS_STANDARD.ORA_NAME_LIST_T.

ORA_INSTANCE_NUM
Returns the number of the database instance.

ORA_IS_ALTER_COLUMN
Returns TRUE if the specified COLUMN_NAME argument is being altered, or FALSE if not.

ORA_IS_CREATING_NESTED_TABLE
Returns TRUE if a nested table is being created, or FALSE if not.

ORA_IS_DROP_COLUMN
Returns TRUE if the specified COLUMN_NAME argument is indeed being dropped, or FALSE if not.

ORA_LOGIN_USER
Returns the name of the Oracle user for which the trigger fired.

ORA_PARTITION_POS
Returns the position in the SQL command where a partitioning clause could be correctly added.

ORA_PRIVILEGE_LIST
Returns the number of privileges being granted or revoked. The PRIVILEGE_LIST argument contains the full list of privileges affected, which is a collection of type DBMS_STANDARD.ORA_NAME_LIST_T.

ORA_REVOKEE
Returns the count of revokees. The USER_LIST argument contains the full list of revokees, which is a collection of type DBMS_STANDARD.ORA_NAME_LIST_T.

ORA_SQL_TXT
Returns the number of lines in the SQL statement firing the trigger. The SQL_TXT argument returns each line of the statement, which is an argument of type DBMS_STANDARD.ORA_NAME_LIST_T.

ORA_SYSEVENT
Returns the type of event that caused the DDL trigger to fire (e.g., CREATE, DROP, or ALTER).

ORA_WITH_GRANT_OPTION
Returns TRUE if privileges were granted with the GRANT option, or FALSE if not.

举例:IF ORA_DICT_OBJ_TYPE = 'TABLE' THEN
    RAISE_APPLICATION_ERROR(-20001,
                            'Can modify database,pls contact dba to do this');
  END IF;
这个时候就是判断如果你的DDL操作的是表,则抛出异常

使用道具 举报

回复
论坛徽章:
0
9#
 楼主| 发表于 2007-5-24 14:05 | 只看该作者
谢谢,我是想要指定当truncate table test的时候,才触发

使用道具 举报

回复
论坛徽章:
0
10#
 楼主| 发表于 2007-5-24 14:06 | 只看该作者
就是要truncate表test的时候才触发,而truncate别的表的时候不触发

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表