11gBuilding an Application Using Oracle Application Express1

75
Overview Purpose This tutorial covers how to build an application, load data and run the application using Oracle Application Express. Time to Complete Approximately 60 minutes Introduction Oracle Application Express (Oracle APEX) is a rapid web application development tool for the Oracle database. Using only a web browser and limited programming experience, you can develop and deploy professional applications that are both fast and secure. Oracle APEX is a fully supported, no cost option of the Oracle database. In this tutorial, you use Oracle APEX Release 4.1.1 to build an application that contains a variety of pages. Prerequisites Before starting this tutorial, you should: o Have access to an Oracle Database 11g database that has the sample schema installed. o Have installed Application Express Release 4.1.1 into your Oracle Database 11g database. o Created a workspace called HR that is based off the HR schema with the admin username of HR and a password of oracle. o Performed the Testing and Debugging Procedures using SQL Developer tutorial. o Downloaded and unzipped the files.zip into your working directory. Using Data Workshop to Load Data into a Table In this topic, you load data into the projects table Double-click the Start Here icon from the Desktop to open the Browser and click the Run APEX bookmark. Enter the following credentials and click Login.

Transcript of 11gBuilding an Application Using Oracle Application Express1

Page 1: 11gBuilding an Application Using Oracle Application Express1

 

Overview

Purpose

This tutorial covers how to build an application, load data and run the application using Oracle Application Express.

Time to Complete

Approximately 60 minutes

Introduction

Oracle Application Express (Oracle APEX) is a rapid web application development tool for the Oracle database. Using only a web browser and limited programming experience, you can develop and deploy professional applications that are both fast and secure. Oracle APEX is a fully supported, no cost option of the Oracle database. 

In this tutorial, you use Oracle APEX Release 4.1.1 to build an application that contains a variety of pages.

Prerequisites

Before starting this tutorial, you should:

o Have access to an Oracle Database 11g database that has the sample schema installed. o Have installed Application Express Release 4.1.1 into your Oracle Database 11g database.o Created a workspace called HR that is based off the HR schema with the admin username of HR

and a password of oracle.o Performed the Testing and Debugging Procedures using SQL Developer tutorial.o Downloaded and unzipped the files.zip into your working directory.

Using Data Workshop to Load Data into a Table

In this topic, you load data into the projects table

Double-click the Start Here icon from the Desktop to open the Browser and click the Run APEX bookmark.

Enter the following credentials and click Login.

Workspace: hrUsername: hrPassword: oracle

Page 2: 11gBuilding an Application Using Oracle Application Express1

Select SQL Workshop > Data Workshop.

Under Data Load, select Text Data.

Page 3: 11gBuilding an Application Using Oracle Application Express1

You want to upload a file and load it into the PROJECTS table. Select Existing table for Load To and click Next.

Select PROJECTS for Table Name and click Next.

Click Browse.

Page 4: 11gBuilding an Application Using Oracle Application Express1

Select the /home/oracle/Desktop/solutions/apexp1_lab/projects.txt file and click Open.

The file is tab delimited. Change the Separator to \t and click Next.

The column mapping information is displayed. Click Load Data.

Page 5: 11gBuilding an Application Using Oracle Application Express1

The data was loaded successfully. In the next topic, you add a Unique Constraint on the EMPLOYEES table.

 

Creating a Database Application Using the Application Wizard

In this topic, you create a database application using the application wizard. You will create a series of pages, these include, a Form on the EMPLOYEES Table with an Interactive Report, a Master Detail Form on the PROJECTS and TASKS table.

Select Application Builder > Database Applications.

Page 6: 11gBuilding an Application Using Oracle Application Express1

Click Create.

Make sure Database is selected and click Next.

Make sure From Scratch is selected and click Next.

Page 7: 11gBuilding an Application Using Oracle Application Express1

Enter Project Tasks Application for Name and click Next.

This wizard window allows you to create pages in your application. Select the Report and Form Page Type and click the List of Values icon to select a table.

Page 8: 11gBuilding an Application Using Oracle Application Express1

Select the EMPLOYEES table link.

Click Add Page.

Page 9: 11gBuilding an Application Using Oracle Application Express1

Your Report and Form pages were added. You also want to add a Master Detail form. Select the Master Detail page type and select the List of Values icon for the Master Table.

Select the PROJECTS table link.

Page 10: 11gBuilding an Application Using Oracle Application Express1

Select the List of Values icon for the Detail Table.

Notice that you only see the tables that are related to the PROJECTS table. Select the TASKS table link.

Click Add Page.

Page 11: 11gBuilding an Application Using Oracle Application Express1

Notice that two pages will be created, a Report of the Master table which you then will select a project from to see the Master Detail page. Click Next.

You want to have one level of tabs. Click Next.

Page 12: 11gBuilding an Application Using Oracle Application Express1

Accept the default and click Next.

You want to specify a default Date Format for this application. Select the List of Values for Date Format.

Select the 12-JAN-2004 date format link.

Page 13: 11gBuilding an Application Using Oracle Application Express1

Accept the default authentication and click Next.

Accept the default theme which is Theme 21and click Next.

Page 14: 11gBuilding an Application Using Oracle Application Express1

To create the application click Create.

Your application was created successfully. Click Run Application.

Page 15: 11gBuilding an Application Using Oracle Application Express1

Enter hr for Username and oracle for Password and click Login.

The Employee report is displayed. Notice that the default date format for the Hire Date is used. Click one of the edit icons in front of one of the rows to see the form.

Page 16: 11gBuilding an Application Using Oracle Application Express1

This page is the Edit Employee form where you can make changes to an employees data. Click the Projects tab.

This is the Projects Report. Click the edit icon in front of one of the rows to see the Master Detail form.

Page 17: 11gBuilding an Application Using Oracle Application Express1

This page contains the Master Detail form showing all the tasks for a particular project. Note there is currently no data in the Tasks table. You will add data into the Tasks table in a later topic. In the next topic, you modify the Employee Report. Click the Application button at the bottom of the window (which is called the Developer Toolbar).

 

Modifying an Interactive Report

Page 18: 11gBuilding an Application Using Oracle Application Express1

In this topic, you modify the Employee Report by and changing query to show the name of the manager instead of the Manager ID, and changing the format of the SALARY column.

To edit the page, click the 1-Employees page icon.

The first time you edit the page, you receive a popup with an explanation of the tree view. Click OK.

Page 19: 11gBuilding an Application Using Oracle Application Express1

Under Regions, double-click the EMPLOYEES Interactive Report.

To see the SQL Query this report is based on, click the Source subtab.

Page 20: 11gBuilding an Application Using Oracle Application Express1

You want to change the SQL query so that the MANAGER_ID shows the last name of the manager instead of the ID.

Replace MANAGER_ID with the following and click Apply Changes.

Page 21: 11gBuilding an Application Using Oracle Application Express1

(select e.LAST_NAME from EMPLOYEES e where e.EMPLOYEE_ID = EMPLOYEES.MANAGER_ID) Manager,

Click Apply Changes to confirm your change.

You want to change the format for SALARY. Double-click the EMPLOYEES Interactive Report again.

Page 22: 11gBuilding an Application Using Oracle Application Express1

Click the Report Attributes tab.

Select the edit icon in front of the SALARY Column Attribute.

Page 23: 11gBuilding an Application Using Oracle Application Express1

Select the List of Values icon for Number/Date Format.

Select the $5,234.10 link.

Page 24: 11gBuilding an Application Using Oracle Application Express1

Click Apply Changes.

Page 25: 11gBuilding an Application Using Oracle Application Express1

In the upper right corner, click the Run Page icon.

Because you changed the SQL query, the new column Manager is not displayed by default. Select the Actions pulldown.

Select Select Columns.

Page 26: 11gBuilding an Application Using Oracle Application Express1

Select Manager from the Do Not Display list and click the Move icon to move it to the Display in Report list.

Select the Manager column and click the Up icon until the column appears under Hire Date.

Page 27: 11gBuilding an Application Using Oracle Application Express1

You do not want to show the Employee Id. Select it from the list and click the Remove icon to move it to the Do Not Display list.

Page 28: 11gBuilding an Application Using Oracle Application Express1

Click Apply.

Notice the Manager is changed to the Last name of the Manager for each employee and the format of the Salary column has changed.

Page 29: 11gBuilding an Application Using Oracle Application Express1

To save the changes you just made, you need save the report. Select Actions > Save Report.

Select As Default Report Settings from the Save pull down.

Page 30: 11gBuilding an Application Using Oracle Application Express1

Click Apply. In the next topic, you create a calendar page for Projects. Select the Application button in the Developer Toolbar.

Page 31: 11gBuilding an Application Using Oracle Application Express1

 

Creating and Manipulating Data in a Calendar

In this topic, you create a calendar with an edit calendar popup that shows the PROJECT_END_DATE for each Project. You change the end date to see how it moves the project link in the calendar.

Click Create Page.

Select the Calendar page type and click Next.

Page 32: 11gBuilding an Application Using Oracle Application Express1

Select Easy Calendar and click Next.

Enter Project Calendar for Page and Region Name and click Next.

Select Use an existing tab set and create a new tab within the existing tab set. Enter Calendar for the Tab Label and click Next.

Page 33: 11gBuilding an Application Using Oracle Application Express1

Select PROJECTS for Table/View Name and click Next.

Select PROJECT_END_DATE for Date Column, PROJECT_NAME for Display Column and click Next.

Shift-select all the columns for Select Columns, select Popup for Open Link in and click Next.

Page 34: 11gBuilding an Application Using Oracle Application Express1

Accept the default and click Next.

To create the calendar, click Finish.

Page 35: 11gBuilding an Application Using Oracle Application Express1

Click Run Page.

Notice that there are no projects listed in the current calendar. Click the Projects tab.

Click the edit icon in front of the Email Integration project.

Page 36: 11gBuilding an Application Using Oracle Application Express1

Change the Project End Date to tomorrow's date and click Apply Changes.

Click the Calendar tab.

Notice that the Project now appears in the calendar on the project end date. You can also change the project from within the calendar. Click the Email Integration link.

Page 37: 11gBuilding an Application Using Oracle Application Express1

The Edit Calendar Entry popup appears. Select a different Project End Date in the current month and click Apply Changes.

The Project link is now in the date you changed it to. Click the Application button in the Developer Toolbar. In the next topic, you create a series of pages that will allow you to upload data into the TASKS table.

Page 38: 11gBuilding an Application Using Oracle Application Express1

 

Adding a Data Upload Wizard

In this topic, you create a series of wizard pages to upload data into the TASKS table.

Click Create Page.

Select the Data Loading page type and click Next.

Page 39: 11gBuilding an Application Using Oracle Application Express1

Enter Load Tasks for Data Load Definition Name, select TASKS for Table Name, and select TASK_ID for Unique Column 1. Then click Next.

You have two lookups that you need to create. In the data file, you have the last name of the employee and so you need to do the lookup to the employees table to get the employee id. Select ASSIGNED_TO for Column Name, select EMPLOYEES for Table Name, select EMPLOYEE_ID for Column Name (of key value), and select LAST_NAME for Uploaded Column. Then click Add.

Page 40: 11gBuilding an Application Using Oracle Application Express1

You also have to perform a lookup for the project. Select PROJECT_ID for Column Name, select PROJECTS for Table Name, select PROJECT_ID for Column Name, and select PROJECT_NAME for Uploaded Column. Then click Add.

Your lookups have been created. Click Next.

Page 41: 11gBuilding an Application Using Oracle Application Express1

You want to create a rule that will change the Task Name to all uppercase. Select TASK_NAME for Column Name, enter Upper Task Name for Name and select To Upper Case for Type. Then click Add.

Click Next.

Accept the default pages that will be created and click Next.

You want to create a new tab. Select Use an existing tab set and create a new tab within the existing tab set and enter Data Load for the New Tab Label and click Next.

Page 42: 11gBuilding an Application Using Oracle Application Express1

You need to specify which page to go to when you press Cancel. Select the List of Values icon.

You want to select the 3 Projects page link.

Enter 3 for the Finish Branch to Page and click Next.

You are ready to create the Data Load Wizard pages. Click Finish.

Page 43: 11gBuilding an Application Using Oracle Application Express1

Click Run Page.

Notice that you see the flow of the wizard on the left. The first wizard page is where you specify the Data Load Source. You want to upload a file with task data. Select Upload file for Import From and click Browse.

Page 44: 11gBuilding an Application Using Oracle Application Express1

Select tasks.txt from the /home/oracle/Desktop/solutions/apexp1_lab directory and click Open.

Page 45: 11gBuilding an Application Using Oracle Application Express1

The tasks.txt file is comma delimited so change the Separator to ',' (comma) and select the Yes checkbox for First Row has Column Names and click Next.

The Data / Table Mappings are displayed. Notice that the Column Name for the third column is not selected. This is because the name of the column in the file does not match the column in the database. Select the COST column from the pull down.

For the next column to the right, select the BUDGET column from the pull down.

Page 46: 11gBuilding an Application Using Oracle Application Express1

Scroll to the right to make sure all the other columns are specified and click Next.

The Data Validation page is displayed. This page displays the data that will be inserted into the database. Notice that the lookups are applied so the PROJECT_ID rather than the PROJECT_NAME will be inserted and the EMPLOYEE_ID instead of the LAST_NAME will be inserted. In addition, the TASK_NAME was transformed to all Uppercase. Click Load Data.

Page 47: 11gBuilding an Application Using Oracle Application Express1

Notice that 16 rows were inserted. Click Finish.

Notice that Page 3 is now displayed. Select the edit icon next to one of the Projects.

Page 48: 11gBuilding an Application Using Oracle Application Express1

The tasks that you loaded are now displayed for this project. Click the Application button in the Developer Toolbar. In the next topic, you create and apply a List of Values (LOV) to some of the items on your page.

 

Creating and Applying List of Values (LOVs)

Page 49: 11gBuilding an Application Using Oracle Application Express1

In this topic, you customize some of the page items to show a list of values (LOVs). You create an LOV on the MANAGER_ID page item and then convert it to a Shared LOV. In addition, you create a Shared LOV to show a list of jobs and then associate the LOV with the JOB_ID page item.

Click Run Application.

Click the edit icon in front of one of the rows in the Employee Report.

Page 50: 11gBuilding an Application Using Oracle Application Express1

Notice that the EMPLOYEE_ID for the Manager is displayed. You want this to be a select list and show the managers last name. Click Edit Page 2 in the Developer Toolbar.

Scroll down the Page Rendering section and right-click the P2_MANAGER_ID page item and select Edit. Alternatively, you can double-click the page item.

Page 51: 11gBuilding an Application Using Oracle Application Express1

Select the Select List quick pick for the Display As field.

Notice that after you change the Display As, the List of Values subtab appears. Select List of Values to go to that section on this page.

Page 52: 11gBuilding an Application Using Oracle Application Express1

You want a list of employees to be dynamically displayed. Click the Create Dynamic List of Values link.

Select the EMPLOYEES table from the list of values (using the icon) or enter the name in the Table or View field. Then click Next.

Page 53: 11gBuilding an Application Using Oracle Application Express1

Select LAST_NAME for Display column and EMPLOYEE_ID for Return Value and click Next. Note you must have a display and return value for each List of Values you create.

The SQL query that will execute for this item is displayed. Click Finish.

Click Apply Changes.

Your changes were saved. Click Run.

Page 54: 11gBuilding an Application Using Oracle Application Express1

Notice that the Managers Last Name is now listed instead of the Managers Employee ID. Select the list icon.

The list of values is displayed. You might want to use this List of Values on other pages in your application. As a result, you want to make it a Shared LOV. Click the Edit Page 2 button in the Developer Toolbar.

Page 55: 11gBuilding an Application Using Oracle Application Express1

Double-click the P2_MANAGER_ID page item to open its property page.

Page 56: 11gBuilding an Application Using Oracle Application Express1

Because you last selected the List of Values subtab, you should be automatically directed to that section. To convert the LOV to a shared LOV, select Convert LOV from the list of Tasks on the right.

The Create Shared LOV window is displayed with the LOV SQL query. Enter EMPLOYEE_LIST for List of Values Name field and click Create.

Page 57: 11gBuilding an Application Using Oracle Application Express1

The LOV was created successfully. To view all the Shared LOVs, select the Shared Components icon in the upper right corner of the page.

Under User Interface, select List of Values.

You want to create another LOV to show a list of Job Titles. This time, you create the Shared LOV and then reference it on the page item properties page. Click Create.

Page 58: 11gBuilding an Application Using Oracle Application Express1

Accept the default and click click Next.

Enter JOB_LIST for name and click the Dynamic radio button. Then click Next.

Change the SQL query to the following and click Create List of Values.

select job_title d, job_id rfrom jobsorder by 1

The JOB_LIST LOV was created successfully. Now you can reference it in your page item for JOB_ID. Click the Edit Page 2 icon in the upper right of this page. Note that this Edit Page icon references the last page you editted.

Page 59: 11gBuilding an Application Using Oracle Application Express1

Scroll down under Page Rendering and double-click the P2_JOB_ID page item.

Select the Select List quick pick link.

Page 60: 11gBuilding an Application Using Oracle Application Express1

Click the List of Values subtab.

Select JOB_LIST from the list of Named LOVs.

Page 61: 11gBuilding an Application Using Oracle Application Express1

If the JOB_ID is empty, you may want to specify a default value. Select Yes for Display Null Value and enter - Select Job - for Null Display Value and click Apply Changes.

Click the Run Page icon in the upper right section of the page.

Page 62: 11gBuilding an Application Using Oracle Application Express1

Notice that the Job Id now displays the title of the job rather than the id. Click Edit Page 2. In the next topic, you create a validation for this page.

 

Creating Validations

In this topic, you create two validations on the Employees page. The first validation checks to make sure the Manager doesn't report to him/her self. The second validation checks to make sure the hire date is less than todays date.

Page 63: 11gBuilding an Application Using Oracle Application Express1

On the Page 2 Properties window, under Page Processing, right-click Validating and select Create Validation.

Make sure Page item is selected and click Next.

Select P2_MANAGER_ID from the list of Page items and click Next.

Enter something like 'Manager not report to self' for Validation Name and click Next. Note that you will receive the error message inline at the field location as well as at the top of the window.

Page 64: 11gBuilding an Application Using Oracle Application Express1

Select PL/SQL for validation type and click Next.

Select Function Returning Boolean and click Next..

Enter the following code in the Validaton Code area, specify an error message, select Yes for Always Execute and click Create Validation.

if :P2_MANAGER_ID != :P2_EMPLOYEE_ID then return true;else return false;end if;

Page 65: 11gBuilding an Application Using Oracle Application Express1

Your validation was created. Click Run.

Select the same last name of the employee you are editing and click Apply Changes.

Page 66: 11gBuilding an Application Using Oracle Application Express1

The error message is displayed inline as well as next to the field. You want to create another validation. Click the Edit Page 2 button in the Developer Toolbar.

Page 67: 11gBuilding an Application Using Oracle Application Express1

You want to create another validation which will make sure that the hire date is before today's date. Under Page Processing, right-click Validating and select Create Validation.

Make sure Page Item is selected and click Next.

Page 68: 11gBuilding an Application Using Oracle Application Express1

Select the P2_HIRE_DATE page item and click Next.

Enter Hire Date must be before today for Validation Name and select Inline with Field for Error Display Location. This time the error message is only displayed next to the field itself. Then click Next.

Select SQL for validation type and click Next.

Page 69: 11gBuilding an Application Using Oracle Application Express1

Select SQL Expression for type of validation and click Next.

Enter TO_DATE(:P2_HIRE_DATE,'DD-MM-YYYY') < SYSDATE for Validation Code, enter some message in the Error Message field and select Yes for Always Execute and click Next.

Page 70: 11gBuilding an Application Using Oracle Application Express1

You only want this validation to execute if the button pressed is Create or Apply Changes (which is a SAVE request). Select Request Is Contained within Expression 1 for Condition Type and enter CREATE,SAVE for Expression 1 and click Create Validation.

Your validation was created. Click Run.

Page 71: 11gBuilding an Application Using Oracle Application Express1

Change the year to 2013 and click Apply Changes.

The error is displayed.

Page 72: 11gBuilding an Application Using Oracle Application Express1

 

Summary

In this tutorial, you have learned how to:

o Use Data Workshop to load data into a tableo Create a database application using the application wizardo Modify an interactive reporto Create and manipulate data in a calendaro Add a data upload wizardo Create and apply a list of valueso Create a validation

Resources

o APEX OTN Home Pageo Oracle Application Express: Developing Web Applications.o Oracle Learning Libraryo Oracle University

Page 73: 11gBuilding an Application Using Oracle Application Express1