Presentation is loading. Please wait.

Presentation is loading. Please wait.

19 Copyright © 2004, Oracle. All rights reserved. Coding PL/SQL Triggers.

Similar presentations


Presentation on theme: "19 Copyright © 2004, Oracle. All rights reserved. Coding PL/SQL Triggers."— Presentation transcript:

1 19 Copyright © 2004, Oracle. All rights reserved. Coding PL/SQL Triggers

2 19-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Describe the different types of triggers Describe sample uses of triggers Write and reference common code Create a PL/SQL library Publish a report as a result of a database event

3 19-3 Copyright © 2004, Oracle. All rights reserved. Types of Triggers in Reports Report: –Five triggers –Report Triggers node in Object Navigator Data Model: –Formula (column) –Filter (group) –Parameter validation Layout: Format trigger on most objects

4 19-4 Copyright © 2004, Oracle. All rights reserved.

5 19-5 Copyright © 2004, Oracle. All rights reserved. Trigger Code Boolean: true false Character Number Date

6 19-6 Copyright © 2004, Oracle. All rights reserved. Using Report Triggers After Parameter Form F Before Report 1 Before Parameter Form page1 Between Pages page2 If > 1 page After Report If readonly=yes 23 F F F

7 19-7 Copyright © 2004, Oracle. All rights reserved.

8 19-8 Copyright © 2004, Oracle. All rights reserved. Using Report Triggers After Parameter Form Example: Build dynamic WHERE clause Query syntax FUNCTION AfterPForm RETURN BOOLEAN IS BEGIN IF :p_customer IS NULL THEN :p_where_clause := ' ' ; ELSE :p_where_clause := ' where id >= :p_customer ' ; END IF; RETURN(TRUE); END; SELECT CUSTOMER_ID, CUSTOMER_NAME FROM CUSTOMERS ORDER BY CUSTOMER_NAME &p_where_clause

9 19-9 Copyright © 2004, Oracle. All rights reserved.

10 19-10 Copyright © 2004, Oracle. All rights reserved. Using Data Model Triggers: PL/SQL Group Filter Restrict records in a group Perform PL/SQL for each record PL/SQL filters result in all records being fetched FUNCTION G_empGroupFilter RETURN BOOLEAN IS BEGIN IF :department_name = ' Operations ' AND :salary > 5000 THEN RETURN(my_function); ELSE RETURN(TRUE); END IF; END;

11 19-11 Copyright © 2004, Oracle. All rights reserved.

12 19-12 Copyright © 2004, Oracle. All rights reserved. Using Data Model Triggers: Parameter Validation Example: Do not allow report output to be sent directly to a printer. You cannot reassign values to parameters or columns in this trigger. FUNCTION DESTYPEValidTrigger RETURN BOOLEAN IS BEGIN IF :DESTYPE = ' Printer ' THEN RETURN(FALSE); ELSE RETURN(TRUE); END IF; END;

13 19-13 Copyright © 2004, Oracle. All rights reserved.

14 19-14 Copyright © 2004, Oracle. All rights reserved. Using Layout Triggers Format triggers: Exist on most layout objects Can suppress an entire layout section (master group frame): No records fetched Can suppress the display of individual records (repeating frame): All records fetched

15 19-15 Copyright © 2004, Oracle. All rights reserved.

16 19-16 Copyright © 2004, Oracle. All rights reserved. Using a Format Trigger on a Frame Dept: f_deptno No employees in this department NameSalary Dept: 10 Dept: 40 No employees in this department 2 1 Displaying a Text String in Place of Column Headings

17 19-17 Copyright © 2004, Oracle. All rights reserved.

18 19-18 Copyright © 2004, Oracle. All rights reserved. Employee Details 1 Using a Format Trigger on a Repeating Frame f_name f_date f_salaryf_name f_date King 17-JUN-87 24000 Kochhar 21-SEP-89 17000 Employee Details De Haan 13-JAN-93 17000 2 King 17-JUN-87 Kochhar 21-SEP-89 Employee Details De Haan 13-JAN-93 3 Dynamically Altering the Display of Records

19 19-19 Copyright © 2004, Oracle. All rights reserved.

20 19-20 Copyright © 2004, Oracle. All rights reserved. Using a Format Trigger on a Field Employee Details f_name f_date f_salary Kochhar 21-SEP-89 17000 Employee Details De Haan 13-JAN-93 17000 King 17-JUN-87 Kochhar 21-SEP-89 Employee Details De Haan 13-JAN-93 King 17-JUN-87 24000 2 1 Dynamically Hiding Fields

21 19-21 Copyright © 2004, Oracle. All rights reserved. Using a Format Trigger in a Web Layout <rw:foreach id="R_G_DEPARTMENT_ID_1" src="G_DEPARTMENT_ID"> … <td class="OraCellNumber"> <rw:field id="F_SALARY" src="SALARY" nullValue=" " formatMask="$999,999.00" formatTrigger="mystyles"> F_SALARY …

22 19-22 Copyright © 2004, Oracle. All rights reserved. f_1f_2f_3 Using a Format Trigger on a Boilerplate Object FUNCTION spacing RETURN BOOLEAN IS BEGIN IF MOD(:count_column, 3) = 0 THEN RETURN(TRUE); ELSE RETURN(FALSE); END IF; END; 2 1 Insert Spacing Between Groups of Records 3 4

23 19-23 Copyright © 2004, Oracle. All rights reserved.

24 19-24 Copyright © 2004, Oracle. All rights reserved. Writing Common Code At the Report level: Object Navigator, Program Units Menu: Program > PL/SQL Editor In a library: Object Navigator, PL/SQL Library File > New: Create new library File > Open: Add to existing library Attach library to report

25 19-25 Copyright © 2004, Oracle. All rights reserved.

26 19-26 Copyright © 2004, Oracle. All rights reserved. Event-Based Reporting Implemented through PL/SQL stored procedures Uses include: –Running a report –Displaying report status –Canceling a report –Managing parameter lists

27 19-27 Copyright © 2004, Oracle. All rights reserved. Event-Driven Publishing API Reports Services Output Data model Data interface Oracle Workflow Client Reports Cache E-mail File Printer PL/SQL Advanced Queuing

28 19-28 Copyright © 2004, Oracle. All rights reserved.

29 19-29 Copyright © 2004, Oracle. All rights reserved. Invoking a Report from a Database Event Create a database trigger Include a parameter list with the required entries: – GATEWAY – SERVER – REPORT – USERID

30 19-30 Copyright © 2004, Oracle. All rights reserved.

31 19-31 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Select the appropriate trigger type for your requirement: Report, Data Model, or Layout Identify the trigger and code needed for: –Building a dynamic WHERE clause –Validating a parameter value –Dynamically altering record display –Suppressing null fields Use Report-level program units and create PL/SQL libraries for common code Invoke a report from a database event

32 19-32 Copyright © 2004, Oracle. All rights reserved.

33 19-33 Copyright © 2004, Oracle. All rights reserved. Practice 19 Overview Creating a format trigger to display different paper layouts conditionally Creating and using a report-level PL/SQL function Creating an using an external PL/SQL library Creating a PL/SQL group filter

34 19-34 Copyright © 2004, Oracle. All rights reserved.

35 19-35 Copyright © 2004, Oracle. All rights reserved.

36 19-36 Copyright © 2004, Oracle. All rights reserved.


Download ppt "19 Copyright © 2004, Oracle. All rights reserved. Coding PL/SQL Triggers."

Similar presentations


Ads by Google