Creating A Simple Database Application in Oracle APEX
Creating A Simple Database Application in Oracle APEX
database application in
Oracle APEX
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Tutorial: Creating a simple database application in Oracle APEX
Topic Details
Overview In this tutorial, you will create a simple
database application in Oracle APEX
using App Builder.
Key Concepts • Create an Application using the
Application Wizard
• Create additional pages using the
Page Wizard
• Use existing sequences to populate
primary key columns
• Create Lists of Values to populate
foreign key columns.
• Create Master Detail Forms
• Upload an image file to display on a
page in the application
Difficulty Intermediate
Duration Approximately 90 minutes
Notes Students should have completed either:
Database Design and Programming with
SQL or Database Foundations prior to
attempting this tutorial.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
2
Part 1: Introduction and getting started
This tutorial will demonstrate how to create a database application using the App Builder component of Oracle Application Express
(APEX).
The application created in this tutorial will allow end-users to add, modify and delete data in the existing Jobs, Employees and
Departments tables without the need to run SQL queries.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
3
Click New Application.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
4
Select an Icon and its color to use for your application, then click Set Application Icon.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
5
Step 5: Add a page to the application
A “Home” page is added automatically to your application, this will be the parent page for any other page that we add.
In this step, we will add a page that will display the data in the jobs table.
Scroll up to the Add Page link and click it.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
6
The Jobs page should show in your application.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
7
You will see your application and the pages it contains. If your pages are displayed as a list, click the view icons button.
Note: Each page has a number in front of it. This is just the order in which they were created. If you delete a page and recreate it will
take a new number. Do not worry if your number does not match these notes.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
8
Step 6: Run and test application
Click the Run Application icon. Your application will open in a new browser window (or tab). Login using your APEX user name and
password.
Once the app is displayed in the browser, click the Jobs page from the navigation pane on the left or by clicking the page icon.
Close the browser window (or tab) showing the running application.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
9
Part 2: Add an Employees page using the Create Page Wizard
From the application home page, click the “Create Page” button to start the Page Wizard.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
10
Step 2: Edit Select Page Type.
Click “Interactive Grid”
11
Leave other fields as the default selection, and click the “Next” button
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
12
Step 4: Select Key.
Enter the following properties for the pages
Primary Key Column 1: EMPLOYEE_ID (Number) (if not already selected)
Leave the rest as default.
Click the “Create Page” button.
The Employees Report will open in the Page Designer view. Click the Application Number to return to the application’s home page.
(Note: your application number will be different).
You will see that you new page has been added to your app, Employees . Click the Run Application icon.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
13
Login with your APEX username and password if prompted, click “Employees Report” from the Navigation Menu, and you will see all
employees displayed. Click the Edit icon next to an employee id.
The Update Employees Form is displayed, which allows employee details to be edited. Do not attempt to modify or insert records at this
time. Close the Update Employee Form by either clicking one of the pages in the Navigation Menu on the left of the window, or scroll
down the Update Employee Form and click the Cancel Button.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
14
Part 3: Include Lists of Values on the Update Employees page.
The employees table has three foreign key columns. In order to successfully insert or update a record, valid values must be used for
these columns that already exist in the parent tables. Using values that are not present in the parent tables will result in an integrity
constraint error when attempting to insert or update a record.
To avoid this happening, we can create Lists of Values (LOVs) that force the user to select only valid values that already exist in the
parent tables.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
15
In the Page Item area, change the Type to “Popup LOV”, and the Label to “Department Name”. You will see errors highlighted, we will
correct these in the next step.
The SELECT clause of the statement selects 2 columns, the first is which value will be displayed in the LOV, and the second which
value will be inserted into the table. In order that the end user does not have to remember the department id for each department, the
LOV will display the name of the department, but when the row is inserted or modified, the corresponding department id will be inserted
into the employee record. Click the “Save” button above the Page Item tab to save your changes.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
16
Step 4: Test the SQL statement is adding correct values.
Run the application and from the Employees Report page, click create.
The Update Employees page will open, scroll down to the Department Name field and click the up arrow to the right of the field. A
popup box should display showing the eight department names contained in the departments table. Do not attempt to modify or insert
records at this time.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
17
Step 5: Edit the job_id item to use a List of Values.
We will now add another LOV for the job_id field, similar to how we did previously.
Ensure page 4 – Update Employees is open in Page Designer. From the Rendering tab, select P4_JOB_ID by left mouse clicking it. (If
the items are not listed, you may need to expand Regions, Content Body and Items).
In the Page Item area, change the Type to “Popup LOV”, and the Label to “Job Title”. You will see errors highlighted, we will correct
these in the next step.
Click Save, and run the application to test, as you did previously with the LOV for departments.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
18
Step 7: Create a shared List of Values.
We will now add another LOV to use for the manager_id field. Later in this Lab, we will create a page to view and modify the
Departments table, which also has a manager_id column. To save duplication of work, we can create the LOV as a Shared Component,
and access it from both pages.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
19
For Name and Type, enter Name: get_managers, Type: Dynamic, then click Next.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
20
For Source Type, select SQL Query.
The SQL statement for this LOV is a little more complicated than the previous examples we have done. Firstly, we want to display both
the manager first name and last name. As these are two different columns in our table, we need to use the concatenation operator (two
“pipe” symbols || ) to display the manager full name as if it were a single column.
We also need to add a WHERE clause as, only employees with a job id of “AD_PRES”, “AD_VP” or employees with the text “_MAN” or
“_MGR” in their job_id can be managers.
Enter the following code in the Code Editor:
Once the statement is entered, click the “Validation icon” (a tick inside a circle), and if you receive a validation successful message,
click Next.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
21
Accept the values for Column Mappings, and click Create.
The List of values will be displayed on the Shared Components LOVs page. Click the Application number to return to the application
home page.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
22
Step 8: Use the Shared List of Values in the Update Employees page.
From the application home page, click Update employee to open the page in Page Designer.
From the Rendering tab, select P4_MANAGER_ID by left mouse clicking it. (If the items are not listed, you may need to expand
Regions, Content Body and Items).
In the Page Item area, change the Type to “Popup LOV”, and the Label to “Manager Name”. You will see errors highlighted, we will
correct these in the next step.
In the “Page Item” area, scroll down to see the List of Values settings. For “Type” select Shared Component, for List of Values, select
GET_MANAGERS. Click Save.
Run the application to test, as you did previously with the LOV for departments and jobs. If you have coded your SQL statement
correctly, the Popup LOV for Manager Name should show only the seven employees that can be managers. Do not attempt to insert a
new record at this time.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
23
Part 4: Use a sequence to manage primary key values on the Update Employees page.
If you tried to insert a new employee on the Update Employee page, you would receive an error message. The employee_id item is
hidden by default, so the user cannot enter a value for the primary key of the table. One solution would be to edit the page and change
the employee_id item’s type from “Hidden” to “Number Field”, and users could then enter a value for the employee_id.
It is however, unrealistic to expect end users to know what value to use for the primary key, especially if the table is large and has many
rows.
We can create a process that will use a sequence, employees_seq (which was created in your schema when you ran the script to
create and populate the tables) to automatically add values for the employee_id column.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
24
Step 2: Enter code for the process.
For the Process name, enter get_pk, ensure Type is set to Execute Code, and in the Source area. Check that Location is Local
Database and language is PL/SQL. Click the icon to open the code editor.
BEGIN
IF :P4_EMPLOYEE_ID IS NULL
THEN
SELECT employees_seq.NEXTVAL
INTO :P4_employee_id
FROM dual;
END IF;
END;
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
25
Once the statement is entered, click the “Validation icon” (a tick inside a circle), and if you receive a validation successful message,
click OK.
The new get_pk process must run before the other process to ensure that employee_id has a value before the insert is processed.
In the processes tab, left mouse click and drag the new get_pk process so that it is above the Process form Update Employees
process. Click Save.
You should receive a message that the insert was successful and see the new employee included in the Report page.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
26
Part 5: Add a new Page to view departments and their employees.
In this section, we will add a Master Detail Form, which will display departments, and the employees that are assigned to each
department on a separate page. The page will also allow the user to update, add and delete departments.
Master Detail refers to the relationship between the two tables. The employees table has a foreign key relationship with the
departments table, so the departments table is known as the “master” table, and employees as the “detail” table.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
27
Select Drill Down.
28
Click Next.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
29
Step 3: Apply Master and Detail settings for Employees.
Select the following:
Name: Department Employees
Table/ View Name: Select Employees
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
30
Step 4: Use LOV for manager id foreign key column.
Ensure Department Employees is open in Page Designer.
From the Rendering tab, select MANAGER_ID by left mouse clicking it. (If the items are not listed, you may need to expand Regions,
Content Body, Form on Departments and items).
In the Page Item area, change the Type to “Popup LOV”, and the Label to “Manager Name”. You will see errors highlighted, we will
correct these in the next step.
In the “Page Item” area, scroll down to see the List of Values settings. For “Type” select Shared Component, for List of Values, select
GET_MANAGER. Click Save.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
31
Step 5: Use LOV for location id foreign key column.
Ensure page 6 – Department Employees is open in Page Designer.
From the Rendering tab, select P6_LOCATION_ID by left mouse clicking it. (If the items are not listed, you may need to expand
Regions, Content Body, Form on Departments and items).
In the Page Item area, change the Type to “Popup LOV”, and the Label to “City”. You will see errors highlighted, we will correct these in
the next step.
In the “Page Item” area, scroll down to see the List of Values settings. For “Type” select SQL Query and enter the following code:
Click Save.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
32
Step 6: Set employee details to be view only.
By default the employees are displayed in an editable interactive grid, which allows users to update employee records. We want users
to manage employee records on the existing Update Employee page. Ensure Page 6 –Department Employees is open in Page
Designer.
From the rendering tab, left click Department Employees to select the form. In the Region tab, change Type from Interactive Grid to
Interactive report. Click Save.
Run your application to test. Do not create a new department at this time.
Part 6: Use a sequence to manage primary key values on the Update Departments page.
In this step, we will create a new process to automatically generate primary key values using an existing sequence when creating a new
department, in the same way we did earlier for the employee_id primary key.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
33
Right click on Processes, and select “Create Process”.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
34
Enter the following code in the code Editor:
BEGIN
IF :P6_DEPARTMENT_ID IS NULL
THEN
SELECT departments_seq.NEXTVAL
INTO :P6_department_id
FROM dual;
END IF;
END;
Once the statement is entered, click the “Validation icon” (a tick inside a circle), and if you receive a validation successful message,
click OK.
The new get_dept_pk process must run before the other process to ensure that department_id has a value before the insert is
processed.
In the processes tab, left mouse click and drag the new get_dept_pk process so that it is above the “Process form Form on
Departments” process.
As we changed the Department Employees to show as an Interactive Report that is not editable, we also need to delete the process to
save the Interactive grid. Right click on the process “Department Employees – Save Interactive Grid Data” and Delete.
Click Save.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
35
Step 3: Run and test.
Run the application and click Departments from the Navigation Menu, then Create.
The new department should be displayed in the Department Report, and a Row created message displayed.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
36
Part 7: Improve appearance of Home page and Navigation menu.
At the moment, the Employees and Departments Navigation Menu items have the icon assigned by default when the pages were
created. In this section we will update the icons, and add tiles to the home page for these pages also.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
37
Click Navigation Menu.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
38
For Image/Class, click the list icon.
Scroll down through the icons, and select the fa-user icon.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
39
Click Apply changes.
Follow the same process to change the Departments Icon, this time select the icon fa-building. Run the application to test, the new
icons will now be shown in the Navigation Menu.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
40
Click Page Navigation.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
41
Click Create Entry
For Image/Class enter fa-user (or browse for the icon using the drop down list). For label, enter Employees Report, and for Page enter
3 or the number you have next to Employees Report.
Click Create and Create Another.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
42
For Image/Class enter fa-building (or browse for the icon using the drop down list). For label, enter Departments, and for Page enter 5
or select the one called Departments. Click Create List Entry.
Return to the application home page, and run the application to test. There should now be 3 navigation tiles showing.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
43
Part 8: Add an image to the Home page.
First find an image you want to use on the Home Page, and save locally on your PC, noting its location. Make sure the image is not too
large, as we want it to fit on screen without the user having to scroll across the page. The size should be no more than 450 pixels wide,
and 200 pixels high.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
44
Click Create File.
Click the Drag and Drop file to browse, locate and select the image you want to use, then click Create.
Your file will be uploaded. Copy the reference into a text document (or take careful note of it) as this is how our application will locate
the file from the home page.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
45
Step 2: Add a Region to the Home Page Content Body.
From the application home page, click page 1 – Home.
Select Page Navigation on the left. Locate the Regions tab, and scroll down to see the Static Content Region. Drag the Static Content
Region into the Region Body..
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
46
The new region will be shown. In the Region tab, enter “Welcome to” as the Title.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
47
The Display image should now be shown in the ITEMS area of the Static Image region. In the Page Item area, for Name, enter
P1_IMAGE, and remove the text for Label. For the Settings Based On field, select “Image URL stored in Page Item Value”
In the Page Item area, scroll down until you see the Source section. For Type select Static Value and for “Static Value”, paste the
reference you copied in Step 1. Click Save.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
48
Drag Welcome to above P1_IMAGE and select Save.
You can go back into the home page layout and drag p1_image into the Region Body of Welcome To.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
49
Save and reload your application.
If you wanted to have the three blocks under the Oracle Academy then drag Page Navigation and drop it on Welcome To in the Body.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
50
This will then create a Sub Region with Page Navigation displayed after the Logo.
Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
51