Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Oracle APEX Cookbook : Second Edition

You're reading from   Oracle APEX Cookbook : Second Edition Get straight into developing modern web applications, including mobile, using the recipes in this brilliant cookbook for Oracle Application Express (APEX). From the basics to more advanced features, it's a reference book and guide in one.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher
ISBN-13 9781782179672
Length 444 pages
Edition Edition
Languages
Arrow right icon
Toc

Table of Contents (21) Chapters Close

Oracle APEX Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Creating a Basic APEX Application 2. Themes and Templates FREE CHAPTER 3. Extending APEX 4. Creating Websheet Applications 5. APEX Plug-ins 6. Creating Multilingual APEX Applications 7. APEX APIs 8. Using Web Services 9. Publishing from APEX 10. APEX Environment 11. APEX Administration 12. Team Development 13. HTML5 and CSS3 14. Mobile 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 on 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 on 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;
    [9672_01_15.txt]
  5. Click on 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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image