29
SECTION 6.0 -----> 第第第第 DEVELOP TRIGGERS 第第第第第

SECTION 6.0

  • Upload
    loc

  • View
    86

  • Download
    3

Embed Size (px)

DESCRIPTION

SECTION 6.0. -----> 第六章节 DEVELOP TRIGGERS 开发触发器. OBJECTIVES. ----->At the end of section 6, you should be able to: 在第六章结束后 , 你将能够 : · Choose the appropriate trigger type and scope for the desired action. 选择确切的触发器类型跟所要做的动作的范围 - PowerPoint PPT Presentation

Citation preview

Page 1: SECTION 6.0

SECTION 6.0

• -----> 第六章节• DEVELOP TRIGGERS

• 开发触发器

Page 2: SECTION 6.0

OBJECTIVES

• ----->At the end of section 6, you should be able to:

• 在第六章结束后 , 你将能够 :

• · Choose the appropriate trigger type and scope for the desired action.

• 选择确切的触发器类型跟所要做的动作的范围• · Encode valid statements and references within the PL/SQL block.

• 对有效状态跟参考使用 PL/SQL 块进行编码• · Write, Edit, and compile triggers.

• 写 , 编辑 , 跟编译触发器• DEVELOP TRIGGERS

• 开发触发器

Page 3: SECTION 6.0

OVERVIEW

• -----> 总体介绍• Alter default processing and add functionality to an Oracle Forms appl

ication with triggers. A trigger is a PL/SQL block of code that is executed every time an associated event occurs while executing the form.

• 使用触发器变更默认处理跟增加功能到一个 Oracle Forms 应用程序 . 一个触发器是一个 PL/SQL 块编码的 , 当每一次执行一个相关联的事件发生时执行一个表单 .

Page 4: SECTION 6.0

Sample Trigger Tasks

• -----> 触发器任务范例• · Validate an item against a column in the database.

• 验证在数据库中一栏的一个项目• · Initiate an action when a button is pressed.

• 初始化一个动作当一个按纽被按下去• · Assign a sequence number for items that represent primary key colu

mns in database tables when a new record is committed.

• 当一个新记录被做出来时在数据库表分配一个序列号给代表初键的项目

Page 5: SECTION 6.0

Sample Trigger Tasks(continue)

• -----> 触发器任务范例– · Customize error and informative messages to the operator.

• 设置错误跟提示信息给操作员• · Alter default navigation.

• 变化初始导航• · Initialize items when a form is first started.

• 当一个表单被开始时 , 初始化项目• · Initialize items for a new item.

• 为新项目初始化项目

Page 6: SECTION 6.0

PLAN FOR TRIGGER DEVELOPMENT

• -----> 触发器开发计划• Trigger Development Considerations

• 触发器开发确认• · What event will cause the trigger to fire?

– (This determines the name of the trigger.)

• 什么时间将导致触发器开火 ( 这决定触发器的名字 )

• · What is the trigger scope: form, block, or item?

– (This determines the level at which the trigger is defined.)

• 触发器的范围多大 ; 表单 , 快 , 或项目• ( 这决定触发器定义的层次 )

• · What action will the trigger perform?

• (This determines the commands and logic required in the PL/SQL block.)

Page 7: SECTION 6.0

触发器将做什么动作

• ----->( 这决定命令跟对 PL/SQL 块的逻辑需要• 1. What possible exceptions may arise?

– (This determines the exception handlers)

Page 8: SECTION 6.0

当发生的时候什么可能免除 ( 这个决定免除操作者 )

• 2. Under what circumstances should the trigger fail?

– (This determines when to raise FORM_TRIGGER_FAILURE.)

• 在什么情况下触发器失效• [ 这个决定什么时候出现 FORM_TRIGGER_FAILURE]

Page 9: SECTION 6.0

DETERMINE THE TRIGGER TYPE AND SCOPE

• -----> 决定触发器类型跟范围• Event processing that occurs for the next item event can cause several

triggers to fire.

• 下一个项目事件能引起多个触发器开火的发生事件处理• Next Item Event Processing

• 下一个项目事件处理• Operator Navigates with a mouse from Item A to Item B

• 操作员使用一个鼠标导航才 A 项目到 B 项目• (xieshouhua1)

Page 10: SECTION 6.0

- SAMPLE TRIGGERS ----> 触发器例子• (1) WHEN-NEW-FORM-INSTANCE

• :DATE2 := SYSDATE;

• :FORM_NAME :SYSTEM.CURRENT_FORM;

• :GLOBAL.ID := 慖 D TITLE';

• (2) POST-QUERY

• :DATE2 := SYSDATE;

• :FORM_NAME :SYSTEM.CURRENT_FORM;

• :ID1_TITLE := :GLOBAL.ID;

• (3) KEY-NEXT-ITEM

• IF :SYSTEM.RECORD_STATUS IN ( 慍 HANGED', 慖 NSERT') THEN

• COMMIT;

• END IF;

• NEXT_RECORD;

Page 11: SECTION 6.0

SAMPLE TRIGGERS(continue) -----> 触发器例子

• (4) WHEN-BUTTON-PRESSED

• BEGIN

– GO_ITEM ( 慜 RDERS.ORDE_APIAREA_NO');

– LIST_VALUES;

– GO_ITEM( 慜 RDDERS.ORDE_BLOCK');

• END;

• SAMPLE TRIGGERS

Page 12: SECTION 6.0

SAMPLE TRIGGERS(continue) -----> 触发器例子• (5) WHEN-VALIDATE-ITEM

• DECLARE

• TL SMALLINT;

• UL SMALLINT;

• BEGIN

• -- Obtain USERID@ep01

• :global.INP :=rtrim(GET_APPLICATION_PROPERTY(USERNAME));

• -- Obtain Current user 抯 password

• :global.INPW ;=rtrim(GET_APPLICATION_PROPERTY (PASSWORD));

• -- Calculate the total length of the input string

• TL :=LENGTH(:GLOBAL.INP);

• -- Calculate the length of the USERID

• (@ep01 has 5 characters)

• UL :TL -5;

• -- Extract USERID

• :GLOBAL.UN := SUBSTR(:GLOBAL.INP,1,UL);

• -- Constuct PASSWORD@ep01

• :GLOBAL.PW := RTRIM(:GLOBAL.INPW) | | 扏 ep01';

Page 13: SECTION 6.0

SAMPLE TRIGGERS(continue)• if :choice= '1' then

• host( 憇 qlplus 憒 | :global.UN | | '/ 抾 |:global.PW | |' @setup_pub_user');

• elsif :choice = '2' then

• host( 憇 qlplus ' | | :global.UN | | '/' | |:global.PW | | ' @setup_rcd_user');

• elsif :choice = '3' then

• host( 憇 qlplus ' | | :global.UN | | '/' | | :global.PW | | ' @setup_pwd_user');

• elsif :choice = '4' then

• host( 憇 qlplus ' | | :global.UN | | '/' | | :global.PW | |'

• @rdcs_public_grant ');

• elsif :choice = '5' then

• host( 憇 qlplus ' | | :global.UN | | '/' | | :global.PW | |'

• @rdcs_recrds_grant ');

• elsif :choice = '6' then

• host( 憇 qlplus ' | | :global.UN | | '/' | | :global.PW | | ' @drop_user ');

• elsif :choice = '7' then

• host( 憇 qlplus ' | | :global.UN | | '/' | | :global.PW | |'

• @drop_user_cascade ');

• elsif :choice = '8' then

• call_form ( 慸 ba_rep');

• else

• null;

• end if;

• END;

Page 14: SECTION 6.0

SAMPLE TRIGGERS• (6)WHEN-VALIDATE-ITEM

• begin

• IF :choice = '1' then

• run_product(REPORTS, 抋 ncil',asynchronous,runtime,filesystem, 抪 aramform=no');

• elsif :choice = '2' then

• run_product(REPORTS, 抶 sec_rkl',asynchronous,runtime,filesystem, 抪 aramform=no');

• elsif :choice = '3' then

• run_product(REPORTS, 抦 aps_rkl',asynchronous,runtime,filesystem, 抪 aramform=no');

• elsif :choice = '4' then

• run_product(REPORTS, 抦 ont_rkl',asynchronous,runtime,filesystem, 抪 aramform=no');

• elsif :choice = '5' then

• run_product(REPORTS, 抯 eis_rkl',asynchronous,runtime,filesystem, 抪 aramform=no');

• elsif :choice = '6' then

• run_product(REPORTS, 抯 tape',asynchronous,runtime,filesystem, 抪 mform=no');

• elsif :choice = '7' then

• run_product(REPORTS, 抴 klog_rkl',asynchronous,runtime,filesystem, 抪 aramform=no');

• elsif :choice = '8' then

• run_product(REPORTS, 抴 ltape',asynchronous,runtime,filesystem, 抪 armform=no');

• ELSE

• NULL;

• END IF;

• end;

Page 15: SECTION 6.0

SAMPLE TRIGGERS

• (7)WHEN-VALIDATE-ITEM

• BEGIN

• if :CHOICE = '3' THEN CALL_FORM( 憆 ms3');

• elsif :CHOICE = '9' THEN CALL_FORM( 憆 ms9');

• elsif :CHOICE = '11' THEN CALL_FORM( 憆 ms800');

• elsif :CHOICE = '12' THEN CALL_FORM( 憃 rder');

• elsif :CHOICE = '13' THEN CALL_FORM( 憈 ransmit');

• elsif :CHOICE = '14' THEN CALL_FORM( 憆 equest');

• elsif :CHOICE = '15' THEN

• CALL_FORM( 憆 ockall');

• elsif :CHOICE in ('1','2','4','5','6','7','8','10') then

• call_form( 憄 ex' | | rtrim(:choice));

• else

• null;

• end if;

• END;

Page 16: SECTION 6.0

Code the PL/SQL Block

• -----> 对 PL/SQL 块进行编码• After determining the trigger name, type, and scope, write the text of t

he trigger, which consists of a PL/SQL block of code

• 在决定触发器名 , 类型跟范围后 , 写包括一个 SL/SQL 块的编码的触发器的程序 ,

• PL/SQL Block Structure

• PL/SQL 块结构• PL/SQL

• PL/SQL

Page 17: SECTION 6.0

Code the PL/SQL Block

• -----> 对 PL/SQL 块进行编码 (table)

• BLOCK SECTION

• 块分段 PURPOSE

• 目的• Declaration

• 声明 Declare local PL/SQL identifiers

• 生命本地 PL/SQL 标识符• Body

• 主要部分 Perform the action of the trigger

• 运行触发器的动作• Exception

• 除外 Handle abnormal conditions when they arise within the body of PL/SQL block

• 控制不正常状态 , 当他们出现在 PL/SQL 块主体时

Page 18: SECTION 6.0

CREATE A TRIGGER

• -----> 创建触发器• Create a new trigger by accessing the Trigger property sheet

• 通过进入触发器属性表创建一个新触发器

Page 19: SECTION 6.0

Steps for Creating a New Trigger

• -----> 建立一个新触发器的步骤• 1. Select the Form, Triggers option from the designer menu to d

isplay the Trigger List window.

• 选择设计器菜单中的 Form, Triggers 选项来显示触发器显示窗口• 2. Press the New button to display a Trigger property sheet.

• 按 NEW 键来显示触发器属性表• 3. Fill out the Trigger property sheet.

• 填充此触发器属性表• 4. (Optional) Press the Compile button to compile the trigger te

xt.

• ( 可选 ) 按 Compile 键来编译触发器文件

Page 20: SECTION 6.0

CREATE A TRIGGER (continued)

• -----> 创建一个触发器• 5. Exit the Trigger property sheet.

• 离开触发器属性表– A. Press the OK button to save the trigger definition.

• A. 按 OK 键来保存触发器定义– B. Press the Cancel button to discard the trigger definition.

• B. 按 Cancel 键来丢弃触发器定义• 6. Press the Close button.

• 按 Close 键

Page 21: SECTION 6.0

Create a Trigger

• -----> 创建一个触发器• Specify the properties for the trigger on the Trigger property sheet.

• 为触发器在触发器属性表指定属性

Page 22: SECTION 6.0

Trigger Property Sheet(table)

• -----> 触发器属性表• PROPERTY

• 属性 COMMENTS

• 说明• Scope

• 范围 For a form-level trigger, choose the Form radio button

• 为一个表格层触发器 , 选择 Form radio 键– For a block-level trigger, choose the Block radio button and enter t

he name of the block.

• 为一个块层触发器 , 选择 Block radio 键并键入块的名字– For an item-level trigger, choose the Item Radio button and enter t

he name of the block and the name of the item.

• 为一个项目层触发器 , 选择 Item Radio 按纽 , 并键入块名跟项目名– Choose the block and item names from the attached LOV 抯 , if de

sired.

• 如果想要的话 , 从相应的 LOV 选择块跟项目名

Page 23: SECTION 6.0

Trigger Property Sheet(table)

• -----> 触发器属性表 (continue)

• Type

• 类型 Choose the Built-in Type and enter the predefined name of the trigger

• 选择 Built-in 类型并键入预先定义的触发器名称– To avoid misspellings, choose the trigger name from the LOV usin

g the auto-reduce feature.

• 避免错误鸣谢 , 使用自动减少特性从 LOV 选择触发器名• Style

• 形式 Always choose PL/SQL

• 一般使用 PL/SQL

• Show Keys For a Key trigger, set the Show Keys check box on to include the key in the operator keyboard map.

• 为一个 Key 触发器 , 设定 Show Keys 复选框来对应包括此键的操作员键盘图

• Enter the description for the key that is to appear on the keyboard map.

• 为此键键入当它出现在键盘图时的描述

Page 24: SECTION 6.0

Trigger Property Sheet(table)

• -----> 触发器属性表 (continue)• Fire in• Query Mode• 在 Query模式启动 Set the check box OFF if the trigger is to fire

in Normal Mode only.

• 如果触发器只在普通模式的启动话设置复选框关闭• Set the check box ON if the trigger is to fire in Enter Query mode, as we

ll as• 如果触发器可以在进入查询模式被出发时 , 设定复选框打开• Trigger Text

• 触发器原文 Enter the PL/SQL block of code.• 键入编码到 PL/SQL 块

Page 25: SECTION 6.0

MODIFY A TRIGGER

• ----->修改一个触发器• Modify an existing trigger by accessing its Trigger property sheet by

way of the Trigger List window.

• 在触发器列表窗口通过进入一个触发器的属性表来修改一个已存在的触发器

Page 26: SECTION 6.0

Steps for Modifying an Existing Trigger

• ----->修改一个已存在触发器的步骤• 1. Select the Form, Triggers option from the designer menu to display the Trigger List win

dow, which contains all previously defined triggers.

• 选择设计器菜单中的 Form, Triggers 选项来显示触发器列表窗口 ,其包括所有预先设定的触发器

• 2. Choose the trigger to modify from the list, then press Edit.

• 从表中选择触发器来修改 , 按 Edit

• A Scroll through the triggers, which are listed alphabetically by scope.

• A 滚动触发器列表 ,其被按字母顺序排列• B. Narrow the list to view only the triggers defined at the form level by setting the Form L

evel, Block Level, and Item Level check boxes on or off, then pressing Find.

• 通过设定 Form 层 , 块层 , 跟项目层复选框开或关 ,然后按 Find 来缩窄列表到只能看到 Form层的触发器定义

• C. Narrow the list to view on the triggers attached to a particular block by setting the Block Level check box on , entering the name of the block, and then pressing Find.

• 通过设定 Block 层复选框开 , 键入块的名字 ,然后按 Find,缩窄列表到只能看到触发器联系到特定块

• D Narrow the list to view only the triggers attached to particular item by setting both the Block Level and Item Level check boxes on, entering the name of the block and item, and then pressing Find.

• 通过设定 Block 层跟 Item 层复选框 on,然后键入块跟项目的名字 ,然后按 Find 来 ,缩窄列表到只能看到联系到特定项目的触发器 .

Page 27: SECTION 6.0

MODIFY A TRIGGER(continue)

• ----->修改一个触发器• 3. Modify the trigger as desired.

• 当你想要的时候 ,修改触发器• A. Modify the text of the PL/SQL code.

• 修改 PL/SQL 码文件• B. Alternatively, change the level of the trigger.

• 选择性的改变触发器的层• 4. Press OK to accept the new definition.

• 按 OK接受新的定义

Page 28: SECTION 6.0

Note

• ----->注意• · Drop an existing trigger by pressing Remove from the Trigger List w

indow.

• 通过按 Remove 从触发器列表窗口去掉一个已存在的触发器• DEVELOP TRIGGERS: SUMMARY

• 开发触发器 : 总结• Develop triggers in order to customize an ORACLE Forms application

beyond the options supplied on the Form, Block, Item, and Window property sheets.

• 开发触发器是为了设置一个 Oracle Forms 应用程序做超出 Form, Block, Item

• 和窗口属性表支持的选项 .

• Steps for Developing a Trigger

• 开发一个触发器的步骤• · Determine the trigger event.

• 决定触发事件

Page 29: SECTION 6.0

Note:(continue)

• · Determine the trigger scope.

• 决定出发范围• · Code the PL/SQL block.

• 对 PL/SQL 块编码• · Fill out the Trigger property sheet.

• 填充触发器属性表• Compile the Trigger.

• 编译触发器• · Save, generate, and run the form.

• · 保存 , 生成并运行表单