290 likes | 414 Views
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. 选择确切的触发器类型跟所要做的动作的范围
E N D
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. • 选择确切的触发器类型跟所要做的动作的范围 • · Encode valid statements and references within the PL/SQL block. • 对有效状态跟参考使用PL/SQL块进行编码 • · Write, Edit, and compile triggers. • 写,编辑,跟编译触发器 • DEVELOP TRIGGERS • 开发触发器
OVERVIEW • ----->总体介绍 • Alter default processing and add functionality to an Oracle Forms application 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块编码的,当每一次执行一个相关联的事件发生时执行一个表单.
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 columns in database tables when a new record is committed. • 当一个新记录被做出来时在数据库表分配一个序列号给代表初键的项目
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. • 为新项目初始化项目
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.)
触发器将做什么动作 • ----->(这决定命令跟对PL/SQL块的逻辑需要 • 1. What possible exceptions may arise? • (This determines the exception handlers)
当发生的时候什么可能免除(这个决定免除操作者)当发生的时候什么可能免除(这个决定免除操作者) • 2. Under what circumstances should the trigger fail? • (This determines when to raise FORM_TRIGGER_FAILURE.) • 在什么情况下触发器失效 • [这个决定什么时候出现FORM_TRIGGER_FAILURE]
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)
- 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;
SAMPLE TRIGGERS(continue) ----->触发器例子 • (4) WHEN-BUTTON-PRESSED • BEGIN • GO_ITEM (慜RDERS.ORDE_APIAREA_NO'); • LIST_VALUES; • GO_ITEM(慜RDDERS.ORDE_BLOCK'); • END; • SAMPLE TRIGGERS
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';
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;
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;
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;
Code the PL/SQL Block • ----->对PL/SQL块进行编码 • After determining the trigger name, type, and scope, write the text of the trigger, which consists of a PL/SQL block of code • 在决定触发器名,类型跟范围后,写包括一个SL/SQL块的编码的触发器的程序, • PL/SQL Block Structure • PL/SQL块结构 • PL/SQL • PL/SQL
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块主体时
CREATE A TRIGGER • ----->创建触发器 • Create a new trigger by accessing the Trigger property sheet • 通过进入触发器属性表创建一个新触发器
Steps for Creating a New Trigger • ----->建立一个新触发器的步骤 • 1. Select the Form, Triggers option from the designer menu to display 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 text. • (可选)按Compile键来编译触发器文件
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键
Create a Trigger • ----->创建一个触发器 • Specify the properties for the trigger on the Trigger property sheet. • 为触发器在触发器属性表指定属性
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 the name of the block. • 为一个块层触发器,选择Block radio键并键入块的名字 • For an item-level trigger, choose the Item Radio button and enter the name of the block and the name of the item. • 为一个项目层触发器,选择Item Radio按纽,并键入块名跟项目名 • Choose the block and item names from the attached LOV抯, if desired. • 如果想要的话,从相应的LOV选择块跟项目名
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 using 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. • 为此键键入当它出现在键盘图时的描述
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 well as • 如果触发器可以在进入查询模式被出发时,设定复选框打开 • Trigger Text • 触发器原文 Enter the PL/SQL block of code. • 键入编码到PL/SQL块
MODIFY A TRIGGER • ----->修改一个触发器 • Modify an existing trigger by accessing its Trigger property sheet by way of the Trigger List window. • 在触发器列表窗口通过进入一个触发器的属性表来修改一个已存在的触发器
Steps for Modifying an Existing Trigger • ----->修改一个已存在触发器的步骤 • 1. Select the Form, Triggers option from the designer menu to display the Trigger List window, 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 Level, 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来,缩窄列表到只能看到联系到特定项目的触发器.
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接受新的定义
Note • ----->注意 • · Drop an existing trigger by pressing Remove from the Trigger List window. • 通过按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. • 决定触发事件
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. • · 保存,生成并运行表单