Home > Building Your Application > Editing the Employees Report
Previous |
Next |
In this exercise, you run a SQL script to create a function that calculates employees' salaries. Then you add a column, Remuneration, to display that calculation in the Employees report.
Topics:
First, create a function to calculate employees' salaries.
To create a function:
Click the Application link on the Developer toolbar (at the bottom of the page).
The Application home page appears.
Click the Home breadcrumb link in the title bar.
Click SQL Workshop and then SQL Commands.
SQL Commands provides a window where you can run PL/SQL against the database.
In the SQL editor, enter the following script:
CREATE OR REPLACE FUNCTION calc_remuneration( salary IN number, commission_pct IN number) RETURN NUMBER IS BEGIN RETURN ((salary*12) + (salary * 12 * nvl(commission_pct,0))); END;
Click Run.
The Results section displays this message:
Function created.
Next, add a column to display the results of the employees' salary calculations.
To add a column:
Navigate to the Page Definition for page 3:
On the SQL Commands page, click the Home breadcrumb link.
On the Workspace home page, click Application Builder.
Select the AnyCo Corp application.
Click 3 - Employees.
The Page Definition for page 3, Employees, appears.
Under Regions, click the Employees link (next to Report).
Scroll down to Source, and replace the existing code with the following:
SELECT "EMPLOYEE_ID", "FIRST_NAME", "LAST_NAME", "HIRE_DATE", "SALARY", "COMMISSION_PCT", calc_remuneration(salary, commission_pct) REMUNERATION FROM "#OWNER#"."OEHR_EMPLOYEES"
Click Apply Changes.
To preview the page, click the Run Page icon in the upper right corner. Notice the addition of the Remuneration column.
Next, change the format of the columns that contain numeric values.
To change the column format:
Click Edit Page 3 on the Developer toolbar (at the bottom of the page).
The Page Definition appears.
Under Regions, click Report.
The Report Attributes page appears.
Locate the Column Attributes section.
Next, change the column and heading alignment for the appropriate columns.
For Column Alignment, select right for SALARY
, COMMISSION_PCT
, and REMUNERATION
.
For Heading Alignment, select center for SALARY
, COMMISSION_PCT
, and REMUNERATION
.
Next, edit the format of the value in the column.
To edit the format of SALARY
:
Under Column Attributes, click the Edit icon next to SALARY
.
The Column Attributes page appears.
For Number/Date Format, select $5,234.10 from the list.
Notice that the appropriate format mask appears in the field.
Click Apply Changes.
Repeat the previous step for REMUNERATION
.
Click the Run Page icon in the upper right corner to preview the page.
Notice that the numbers in the Salary and Remuneration columns now appear with the dollar sign, include commas and decimals, and are correctly aligned.