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

Slides:



Advertisements
Similar presentations
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
Advertisements

Using the Set Operators
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
A Guide to Oracle9i1 Creating Database Reports Chapter 7.
Project Implementation for COSC 5050 Distributed Database Applications Lab4.
© 2007 by Prentice Hall10-1 Introduction to Oracle 10g Chapter 10 Creating and Modifying Reports James Perry and Gerald Post.
7 Copyright © Oracle Corporation, All rights reserved. Producing Readable Output with i SQL*Plus.
Start First step Create a new blank database Create a database using the option that will enable you to build your database using pre-set options. Save.
Create a new blank database First step SUBMITTry again.
Copyright Ó Oracle Corporation, All rights reserved Sharing Objects and Code.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
7 Copyright © 2004, Oracle. All rights reserved. Working with Text Items.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
4 Copyright © 2004, Oracle. All rights reserved. Creating a Basic Form Module.
Chapter 7: Creating Database Reports
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using the Set Operators Assist. Prof. Pongpisit Wuttidittachotti, Ph.D. Faculty.
5 Copyright © 2004, Oracle. All rights reserved. Creating a Master-Detail Form.
1 Chapter 5: Introduction To Form Builder. 2 Forms  Why Do We Use Form Builder?  Why Don’t We Use SQL Only?!
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
Copyright  Oracle Corporation, All rights reserved. 4 Creating Functions.
Project Implementation for COSC 5050 Distributed Database Applications Lab5.
23 Copyright © 2004, Oracle. All rights reserved. Sharing Objects and Code.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
6 Copyright © 2004, Oracle. All rights reserved. Working with Data Blocks and Frames.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
PowerBuilder Online Courses - by Prasad Bodepudi
5 Copyright © 2004, Oracle. All rights reserved. Creating a Master-Detail Form.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Copyright  Oracle Corporation, All rights reserved. 4 Accessing a Database Using JBCL.
4 Copyright © 2004, Oracle. All rights reserved. Creating a Basic Form Module.
5 Copyright © 2004, Oracle. All rights reserved. Creating a Master-Detail Form.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Copyright  Oracle Corporation, All rights reserved. 5 More on Creating Database Forms Using AppBuilder.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
16 Copyright © 2004, Oracle. All rights reserved. Adding Functionality to Items.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Implementing The Middle Tier These slides.
Copyright  Oracle Corporation, All rights reserved. 8 Producing Readable Output with SQL*Plus.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
4 Copyright © 2004, Oracle. All rights reserved. Creating a Basic Form Module.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
6 Copyright © 2004, Oracle. All rights reserved. Adding Custom Validation.
5 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Working with Layout Editor.
21 Copyright © 2009, Oracle. All rights reserved. Working with Oracle Business Intelligence Answers.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
15 Copyright © 2004, Oracle. All rights reserved. Debugging Triggers.
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
Copyright Ó Oracle Corporation, All rights reserved. 77 Creating LOVs and Editors.
D Copyright © 2004, Oracle. All rights reserved. Using Oracle XML Developer’s Kit.
11 Copyright © 2004, Oracle. All rights reserved. Managing XML Data in an Oracle 10g Database.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
17 Copyright © 2006, Oracle. All rights reserved. Information Publisher.
Preface IIntroduction Course Objectives I-2 Course Content I-3 1Introduction to Oracle Reports Developer Objectives 1-2 Business Intelligence 1-3 Enterprise.
1 Chapter 6: Creating Oracle Data Block Forms. 2 Forms  Application with a graphical user interface that looks like a paper form  Used to insert, update,
9 Copyright © 2007, Oracle. All rights reserved. Creating Stored Procedures and Functions.
13 Copyright © 2004, Oracle. All rights reserved. Migrating SQL Statements.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
D Copyright © 2009, Oracle. All rights reserved. Using SQL*Plus.
CHAPTER 7 LESSON B Creating Database Reports. Lesson B Objectives  Describe the components of a report  Modify report components  Modify the format.
Working in the Forms Developer Environment
Creating LOVs and Editors
Introduction to Triggers
Using SQL*Plus.
Creating Noninput Items
Creating a Master-Detail Form
Using SQL*Plus.
Presentation transcript:

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

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

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

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

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

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

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

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

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

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;

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

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;

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

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

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

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

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

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 Kochhar 21-SEP Employee Details De Haan 13-JAN King 17-JUN-87 Kochhar 21-SEP-89 Employee Details De Haan 13-JAN-93 3 Dynamically Altering the Display of Records

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

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 Employee Details De Haan 13-JAN King 17-JUN-87 Kochhar 21-SEP-89 Employee Details De Haan 13-JAN-93 King 17-JUN Dynamically Hiding Fields

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 …

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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