Book Image

Oracle APEX 4.0 Cookbook

By : Michel Van Zoest, Marcel Van Der Plas
Book Image

Oracle APEX 4.0 Cookbook

By: Michel Van Zoest, Marcel Van Der Plas

Overview of this book

<p>Oracle Application Express 4.0 is a rapid web application development tool that works with the Oracle database. Using features like Plug-ins and Dynamic Actions, APEX helps you build applications with the latest techniques in AJAX and JavaScript.</p> <p>The Oracle Application Express 4.0 Cookbook shows you recipes to develop and deploy reliable, modern web applications using only a web browser and limited programming experience. <br /><br />With recipes covering many different topics, it will show you how to use the many features of APEX 4.0.<br /><br />You will learn how to create simple form and report pages and how to enhance the look of your applications by using stylesheets. You will see how you can integrate things such as Tag Clouds, Google Maps, web services, and much more in your applications. Using Plug-ins, Dynamic Actions, BI Publisher, translations and Websheets, you will be able to enhance your applications to a new level in APEX.</p> <p>This book will show you how to be Agile in the development of your web applications by using Team Development, debugging, and third-party tools.</p> <p>After reading this book, you will be able to create feature-rich web applications in Application Express 4.0 with ease and confidence.</p>
Table of Contents (19 chapters)
Oracle APEX 4.0 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a computation


Computations are events that will prepare items with data. As the name implies, computations can 'compute' how data is to be shown on screen or how data is handled after submitting. Computations can be triggered during Page Rendering, but they can also be used in the After Submit process.

This example will show an implementation of a computation, but there are many more possible uses for computations.

How to do it...

Start by creating a normal text item on the form that was created in the second recipe of the first chapter. This is a normal form based on the EMP table. Normally, a user would have to manually enter the commission. What we are going to do is to create a computation that will automatically enter an amount into this field, based on a percentage of the salary and a bonus for people that work in the Sales department.

First, identify the item that holds the commission column.

The next step is to find the moment when we want to execute the computation. In this case, before the page is submitted but after the Save button is pressed. So in this case we will create the computation After Submit.

  1. Right-click on the Computations under After Submit in the Page Processing component and click Create.

  2. Choose Item on this page and press Next.

  3. Select P5_COMM from the Compute Item select list, select PL/SQL Function Body from the Computation Type select list and click Next.

  4. The next step is to enter the PL/SQL code for this computation:

    declare
      l_comm number;
    begin
      if :P5_DEPTNO = 30
      then
        l_comm := :P5_SAL * 1.10;
      else
        l_comm := :P5_SAL * 1.05;
      end if;
      return l_comm;
    end;

    [1346_01_15.txt]

  5. Press Create.

The computation is now done. It can be tested by selecting an existing record from the list of employees and altering its salary and then saving the data. Another option is to create a completely new employee. You will see that an employee under the Sales department with dept no. 30 will receive a 10 percent commission whilst employees from all other departments will receive 5 percent.

There's more...

Computations can be used for far more situations than preparing an item before saving it to the database.

An example of another implementation can be an item that will show the current date when the page loads, or an item that will show a total amount when certain other amount items are entered. Used with dynamic actions, computations can be very powerful.