ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:20.61KB ,
资源ID:16568341      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/16568341.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(第25讲 触发器的类型建立修改删除应用Word文件下载.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

第25讲 触发器的类型建立修改删除应用Word文件下载.docx

1、4) AFTER 触发器:在insert, update, delete 语句之后运行。OLD.字段名NEW.字段名在审计应用程序中经常使用AFTER行级触发器,因为直到行被修改才触发这些触发器。行的成功修改表明数据已经通过表的各种约束。5) INSTEAD OF触发器:使用INSTEAD OF 触发器,告诉Oracle要作的事情,而不是执行调用触发器的操作。6) 模式触发器 (Schema trigger)可以在模式级操作上建立触发器,如:create table, alter table, drop table, rename, revoke, grant 等操作上建立触发器。模式级触发器

2、的作用为: 阻止执行DDL操作 或发生DDL操作时进行额外的安全监控。7) 数据库级触发器 (Database Level Trigger )可以在数据库级事件上建立触发器,如错误,注册,注销,关闭,启动等事件。使用数据库级触发器进行自动的数据库维护,或审计活动。4. 触发器创建和修改语法:(只给出最常用的触发器类型定义)CREATE OR REPLACE TRIGGER schema_name.trigger_name BEFORE | AFTER | INSTEAD OF delete | insert | update of column_name, or delete | insert

3、 | update of column, . ON table_name FOR EACH ROW WHEN condition DECLARE 变量定义;BEGIN 语句; 。END;1) 触发器的名字在方案下必须唯一。不能与表,视图,存储过程,函数等同名。2) 触发器的名字必须时合法的Oracle标识,长度为30字符以内。3) 使用FOR EACH ROW为行级触发器,否则为语句级触发器。4) 使用WHEN 子句进一步限定触发器执行,当满足条件时才执行触发器。5) WHEN子句的条件中可以使用新值,旧值。在WHEN 条件中引用新值和旧值不用使用 :OLD, :NEW, 直接使用 NEW.字

4、段名, OLD.字段名。6) 在PL/SQL中使用新值和旧值,必须使用 冒号开头的NEW 和OLD. :NEW, :OLD。7) 触发器中的事务处理类型为: inserting, deleting, updating. 当在一个触发器中同时使用2种以上的DML语句时,应该判断执行的是什么操作。如果是insert 语句,则 INSERTING为true, 如果是update语句,则UPDATING为true, 如果执行DELETE语句,则DELETING为true. 一般使用 IF inserting THEN 语句进行判断。8) 不要在触发器中编写大段的代码,应该将代码写在存储过程中,在触发器

5、中调用存储过程。 Call 存储过程名(参数,。);最简单的触发器创建语法:create or replace trigger document_insert_eventafter insert on Documentfor each rowdeclarebeginend;触发器创建的例子:create or replace trigger Trigger_001before updateon empwhen (new.salold.sal) insert into TEMP001 (no, name) values(:old.ename, :old.sal);5. 创建DDL级触发器:1)

6、建立在DDL操作上的触发器。2) 可以利用DDL事件触发器来执行在簇,函数,索引,包,过程,角色,序列,同义词,表,表空间,触发器,类型,用户,视图上执行create, alter 和drop命令时的执行代码。3) 创建DDL级触发器的例子:create or replace trigger TT02after create on schema call insert_audit_record(ora.dict_obj_name);6. 创建数据库级的触发器 Table 16-1 System Defined Event Attributes AttributeTypeDescriptionE

7、xampleora_client_ip_addressVARCHAR2Returns the IP address of the client in a LOGON event, when the underlying protocol is TCP/IPif (ora_sysevent = LOGON) then addr := ora_client_ip_address;end if;ora_database_nameVARCHAR2(50)Database name.DECLARE db_name VARCHAR2(50); db_name := ora_database_name;or

8、a_des_encrypted_passwordThe DES encrypted password of the user being created or altered.IF (ora_dict_obj_type = USER THEN INSERT INTO event_table(ora_des_encrypted_password);END IF;ora_dict_obj_nameVARCHAR(30)Name of the dictionary object on which the DDL operation occurred.INSERT INTO event_table (

9、Changed object is | ora_dict_obj_name);ora_dict_obj_name_list (name_list OUT ora_name_list_t)BINARY_INTEGERReturn the list of object names of objects being modified in the event.ASSOCIATE STATISTICS then number_modified :(name_list);ora_dict_obj_ownerOwner of the dictionary object on which the DDL o

10、peration occurred.INSERT INTO event_table (object owner isora_dict_obj_ownerora_dict_obj_owner_list(owner_list OUT ora_name_list_t)Returns the list of object owners of objects being modified in the event. then number_of_modified_objects :ora_dict_obj_owner_list(owner_list);ora_dict_obj_typeVARCHAR(2

11、0)Type of the dictionary object on which the DDL operation occurred.This object is a ora_dict_obj_type);ora_grantee( user_list OUT ora_name_list_t)Returns the grantees of a grant event in the OUT parameter; returns the number of grantees in the return value.GRANT) thennumber_of_users :ora_grantee(us

12、er_list);ora_instance_numNUMBERInstance number.IF (ora_instance_num = 1) THEN INSERT INTO event_table 1ora_is_alter_column( column_name IN VARCHAR2)BOOLEANReturns true if the specified column is altered.ALTER andora_dict_obj_type = TABLE then alter_column :ora_is_alter_column(FOOora_is_creating_nest

13、ed_tableReturn TRUE if the current event is creating a nested tableCREATE and ora_is_creating_nested_table) then insert into event_tab values (A nested table is createdora_is_drop_column( Returns true if the specified column is dropped. then drop_column :ora_is_drop_column(ora_is_servererrorReturns

14、TRUE if given error is on error stack, FALSE otherwise.IF (ora_is_servererror(error_number)Server error!ora_login_userVARCHAR2(30)Login user name.SELECT ora_login_user FROM dual;ora_partition_posIn an INSTEAD OF trigger for CREATE TABLE, the position within the SQL text where you could insert a PART

15、ITION clause.- Retrieve ora_sql_txt into- sql_text variable first.n := ora_partition_pos;new_stmt :substr(sql_text, 1, n-1) | | my_partition_clause | | substr(sql_text, n);ora_privilege_list(privilege_list OUT Returns the list of privileges being granted by the grantee or the list of privileges revo

16、ked from the revokee in the OUT parameter; returns the number of privileges in the return value. or ora_sysevent = REVOKE then number_of_privileges :ora_privilege_list(priv_list);ora_revokee (user_list OUT Returns the revokees of a revoke event in the OUT parameter; returns the number of revokees in

17、 the return value.) thenora_revokee(user_list);ora_server_errorGiven a position (1 for top of stack), it returns the error number at that position on error stacktop stack error ora_server_error(1);ora_server_error_depthReturns the total number of error messages on the error stack.= ora_server_error_

18、depth;- This value is used with- other functions such as- ora_server_errorora_server_error_msg (position in binary_integer)Given a position (1 for top of stack), it returns the error message at that position on error stackstack error messageora_server_error_msg(1);ora_server_error_num_params Given a

19、 position (1 for top of stack), it returns the number of strings that have been substituted into the error message using a format like %s.ora_server_error_num_params(1);ora_server_error_param (position in binary_integer, param in binary_integer)Given a position (1 for top of stack) and a parameter n

20、umber, returns the matching , %d, and so on substitution value in the error message.- E.g. the 2rd %s in a message- like Expected %s, found %sparam :ora_server_error_param(1,2);ora_sql_txt (sql_text out Returns the SQL text of the triggering statement in the OUT parameter. If the statement is long,

21、it is broken up into multiple PL/SQL table elements. The function return value specifies how many elements are in the PL/SQL table.sql_text ora_name_list_t;stmt VARCHAR2(2000);.= ora_sql_txt(sql_text);FOR i IN 1.n LOOP stmt := stmt | sql_text(i);END LOOP;text of triggering statement:stmt);ora_syseve

22、ntVARCHAR2(20)System event firing the trigger: Event name is same as that in the syntax.(ora_sysevent);ora_with_grant_optionReturns true if the privileges are granted with grant option.ora_with_grant_option = TRUE) then insert into event_table with grant optionspace_error_info(error_number OUT NUMBE

23、R,error_type OUT VARCHAR2,object_owner OUT VARCHAR2,table_space_name OUT VARCHAR2,object_name OUT VARCHAR2,sub_object_name OUT VARCHAR2)Returns true if the error is related to an out-of-space condition, and fills in the OUT parameters with information about the object that caused the error.if (space

24、_error_info(eno, typ, owner, ts, obj, subobj) = TRUE) dbms_output.put_line(The object | obj | owned by | owner | has run out of space.创建数据库级触发器的例子:create or replace trigger TT003_ON_DATABASEafter startup on database null;Client EventsClient events are the events related to user logon/logoff, DML, and DDL operations. For example:CREATE OR REPLACE TRIGGER On_Logon AFTER LOGON ON The_user.Schema BEGIN Do_Something;7. 触发器删除DROP TRIGGER trigger_name触发器删除例子:drop trigger TT0018.

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1