Manipulating Database Objects

Purpose

This tutorial shows you how to manipulate database objects using Oracle Application Express.

Time to Complete

Approximately 30 minutes.

Topics

This tutorial covers the following topics:

 Overview
 Prerequisites
 Creating a Table from a Spreadsheet
 Adding a Master Table
 Modifying a Table
 Adding a Table Using a Script
 Adding a Constraint
 Summary

Viewing Screenshots

 Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.

Overview

What Is Oracle Application Express?

Oracle Application Express 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.

What Components Make Up Oracle Application Express?

Oracle Application Express contains four main components:

Application Builder

Used to build database-centric interactive Web applications.

SQL Workshop Used to access database objects, run SQL statements and SQL scripts.
Utilities Used to Load and Unload data, Generate DDL, run Object Reports and manage the Recycle Bin.
Administration Used to manage services and users and to monitor activity.

Terminology

The following concepts are important to know when working with Oracle Application Express:

Workspace

A workspace is a virtual private database allowing multiple users to work within the same Oracle Application Express installation but keeping their objects, data and applications private.

Application

An application is a collection of pages with branches that connect them. Its attributes include the authentication method, default UI templates, and authorization rules.

Page A page is the basic building block of an application. When you build an application in Application Builder, you create pages that contain user interface elements, such as tabs, lists, buttons, items, and regions.
Region Content is displayed in regions, which are logical subsections of a page. Each page can have any number of regions of several different types. These types include: HTML text, SQL Queries, PL/SQL-generated HTML, and charts. Each region is rendered using a region template. Regions are positioned on the page using display points defined in the page template.
Item An item can be a text field, text area, password, select list, check box, and so on. Item attributes affect the display and behavior of items on a page. For example, these attributes can impact where a label displays, how large an item is, and whether or not the item is displayed next to, or below the previous item.  The value of an item is automatically stored into the application's session state, which can be referenced at any point within the user's session.

Architecture

Oracle Application Express lives completely within your Oracle database. It is comprised of nothing more than data in tables and large amounts of PL/SQL code. The essence of Oracle Application Express is approximately 165 tables and 200 PL/SQL objects containing 300,000+ lines of code.

Whether you are running the Oracle Application Express development environment or an application you built using Oracle Application Express, the process is the same.   Your browser sends a URL request that is translated into the appropriate Oracle Application Express PL/SQL call.   After the database processes the PL/SQL, the results are relayed back to your browser as HTML.   This cycle happens each time you either request a page or submit a page.   The method behind the url translation depends on your Oracle version.   Running Oracle Application Express in Oracle prior to 10.2.0.3 requires Apache and mod PL/SQL.   In Oracle 10.2.0.3 and beyond, including Oracle Express Edition (XE), Oracle Application Express can use the embedded PL/SQL gateway or Apache.

The application session state is managed in database tables within Oracle Application Express and does not use a dedicated database connection. Minimal CPU resources are consumed in the Application Express environment. If a user requests a page and is mentally processing the resultant page before making another request, the database could be stopped and restarted during the user’s think time without any perceived outage by the user.

What is new in Oracle Application Express 3.1?

This release includes several major new features and enhancements.

Interactive Reports

Interactive Reporting Regions enable end users to customize reports. Users can alter the layout of report data by choosing the columns they are interested in, applying filters, highlighting, and sorting. They can also define breaks, aggregations, different charts, and their own computations. Users can create multiple variations of the report and save them as named reports and download to various file formats including comma-delimited file (CSV) format, Microsoft Excel (XLS) format, Adobe Portable Document Format (PDF), and Microsoft Word Rich Text Format (RTF).

Declarative BLOB Support

Declarative BLOB support enable files to be declaratively uploaded in forms, and downloaded or displayed using reports. BLOB display and download can also be authored procedurally using PL/SQL.

Enhanced Report Printing Report Queries now support multiple SQL statements, which allows for including multiple reports in a single document or combining reports and charts based on different result sets. The output format of a print document can now be set at runtime using a page or application item. In addition to PDF, Word, Excel and HTML, documents can now also be downloaded in XML format. Both report queries and report regions now allow specifying the method of how the print document is downloaded to the client, either as an attachment, displaying a file download / save dialog or showing the document inline within the browser window. The column sizing for print documents based on report regions has also been improved, now supporting sizing based on points in additional to percentage.
Adding to the Theme Repository In addition to the default themes provided with Oracle Application Express, you can now add to the theme repository This enables you to design a very specific look and feel to meet your corporate requirements and then publish this as a theme for all other applications to use. This can be done at the workspace level (Workspace Themes) or at the instance level (Public Themes). Two new standard themes have also been added.
Optional Runtime-Only Installation For testing and production instances, Oracle Application Express, release 3.1 supports the ability to install just a runtime version of Oracle Application Express. This minimizes the installed footprint and privileges. Scripts are also provided to remove or add the developer interface from an existing instance. This new feature improves application security since in a runtime instance developers cannot advertently update a production application.
Improved Security There is a new 'Hidden and Protected' item type. Items of this type, after having been emitted in HTML and sent to the browser, cannot be altered in the page's HTML source and then POSTed to the application using that page. This, together with other minor improvements, makes the default security functionality more robust within Oracle Application Express.
Documented JavaScript libraries You now have the ability to suppress standard JavaScript and CSS files. All included JavaScript files have been compressed to improve page load time. The framework has also been improved to allow advanced Oracle Application Express developers to build and leverage custom Web 2.0 capabilities. This increases performance and enables developers to create more dynamic application widgets.
Application Date Format

You can define a date format that will be used throughout your application. This date format will be used to alter the NLS_DATE_FORMAT database session setting prior to showing or submitting any page within the application. This format is used by all reports showing dates and is also picked up by form items of type "Date Picker (use Application Date Format)". This can be set using:

  1. Application Builder > Application Builder Defaults (under Tasks): These are specific to a Workspace, not a developer, and will be used as the default when using the create application wizard.
  2. Application Builder > Create Application Wizard > Attributes page
  3. Application Builder > Your Application > Shared Components > Edit Globalization Attributes

Back to Topic List

Prerequisites

Before you perform this tutorial, you should:

1.

Install Oracle Database 11g.

2.

Install and configure Oracle Application Express. See documentation on OTN.

3.

Download and unzip the apexintro.zip into your working directory.

Back to Topic List

Creating a Table from a Spreadsheet

To load the data for this tutorial from a spreadsheet, perform the following steps:

1.

Enter the following URL to log in to Oracle Application Express(change the <hostname> to localhost, your specific hostname or apex.oracle.com).

http://<hostname>:8080/apex

 

2.

To log in to Oracle Application Express, enter the following details, and click Login.

Workspace: <your workspace name>
Username: <your username>
Password: <your password>

 

3.

To create the table, click the down arrow next to Utilities > Data Load/Unload > Load.

 

4.

Click Load Spreadsheet Data.

 

5.

Ensure that the import target (Load To) is set to New table. For Load From, select the Upload file (comma separated or tab delimited) option. Click Next >.

 

6.

Click Browse...

 

7.

Locate the tasks.txt file (where you downloaded and unzipped the prerequisite files) and click Open. Because the data in the text file is tab delimited, enter \t in the Separator field. Click Next >.

8.

The Table Information page displays the columns in the table and their formats, as well as the data to be inserted into the table after the table is created. For Table Name, enter OBE_TASKS, and click Next >.

 

9.

Using the Primary Key page, you can add a system-generated primary key to your table and populate that column with a new sequence. Review the default values, and click Load Data.

 

10.

After the table is created and the data is loaded, you are left on the Files page. You can see the file that you just uploaded with 16 rows successfully uploaded. To view your new table, click the SQL Workshop tab.

 

11.

Select the down arrow next to Object Browser > Browse > Tables.

 

12.

To view the table definition, click the OBE_TASKS table under the list of tables in the left navigator.

 

13.

This page displays the table definition. To view the data in the table, click the Data tab.

 

14.

You see all the data in the table. You can change any of the data in the table from this page, and also add rows to the table.

 

Back to Topic List

Adding a Master Table

To make the project name maintainable and to be able to track other information about a project, you can move the Project information into a separate table. Perform the following steps:

1.

Click the Table tab .

 

2.

Click Create Lookup Table button.

 

3.

To specify the column on which the master table is to be created, select PROJECT - varchar2, and click Next > .

 

4.

Enter the following values, and click Next >.

New Table Name: OBE_PROJECTS
New Sequence: OBE_PROJECT_SEQ

 

5.

Click Finish.

 

6.

Notice that the new OBE_PROJECTS table contains a numeric primary key along with the PROJECT column.

 

Back to Topic List

Modifying a Table

Now that you have the two main tables, enhance the OBE_PROJECTS table by adding some additional columns.
To do this, perform the following steps:

1.

Make sure the OBE_PROJECTS table is selected. You are going to add a column to the table. Click Add Column.

 

2.

Enter the following values, and click Next >.

Add Column: PROJECT_DEADLINE
Type: DATE

 

3.

Click Finish.

 

4.

You see the modified table definition with the new PROJECT_DEADLINE column added. You want to create one more column for PROJECT_PRIORITY. Click Add Column.

 

5.

Enter the following values, and click Next >.

Add Column: PROJECT_PRIORITY
Type: NUMBER
Precision: 1

 

6.

Click Finish.

 

7.

The PROJECT_PRIORITY column is added. Click the Data tab to view the data.

 

8.

You see all the projects that were referenced in the OBE_TASKS table. You can change data from here. Click the Edit icon (  ) on the left of PROJECT_ID for Public Website.

9.

For Project Deadline, enter one month from today's date. Enter 1 for Priority. Then click Apply Changes.

10.

You see the data that you added. Another way to create database objects and load data is to use a script. Select SQL Scripts from the drop down list box.

Back to Topic List

Adding a Table Using a Script

You may have noticed that the OBE_TASKS.ASSIGNED_TO column was a number. In this topic, you run a script to create the OBE_EMPLOYEES table and load a list of current employees. Each employee has an EMPLOYEE_ID that corresponds to the numbers found in the OBE_TASKS.ASSIGNED_TO column. Perform the following steps:

1.

Click Upload.

 

2.

Click Browse...

 

3.

Select employees.sql (where you downloaded and unzipped the prerequisite files) and click Open. Enter OBE_EMPLOYEES for the Script Name and click Upload.

 

4.

Select the OBE_EMPLOYEES script.

5.

The script is shown. Click Run.

6.

Click Run to confirm.

7.

The script was executed. To view the results, click the View Results icon.

8.

The OBE_EMPLOYEES table was created and some data was inserted. Click the SQL Workshop breadcrumb.

Back to Topic List

Adding a Constraint

You now have the employee data that is referenced by the OBE_TASKS.ASSIGNED_TO column but need to identify a foreign key between the tables. The foreign key ensures that each ASSIGNED_TO column references a valid Employee. It also ensures that an Employee cannot be deleted who has tasks assigned. Perform the following steps:

1.

Select the down arrow next to Object Browser > Browse and then select Tables.

 

2.

Select the OBE_TASKS table and click the Constraints tab.

 

3.

Click Create.

 

4.

Select Foreign Key for the Constraint Type. Select ASSIGNED_TO for the Foreign Key Column, select OBE_EMPLOYEES for the Reference Table Name and select EMPLOYEE_ID from the Reference Table Column List. Then click Next > .

 

5.

Click Finish.

6.

The constraint was created successfully. You want to also create a check constraint on the PROJECT_PRIORITY column so that the data is validated when the data is inserted or updated. Select OBE_PROJECTS.

7.

Click the Create section tab.

8.

Select PROJECT_PRIORITY for the Constraint of Column field and enter in ('1','2','3') for the Constraint Expression. Ensure that Check Constraint Type is selected. Then click Next >.

9.

Click Finish.

10.

The constraint was created successfully. Click the Home breadcrumb.

Back to Topic List

 

Summary

In this tutorial, you learned how to:

 Create a table
 Modify a table

Back to Topic List

 Place the cursor over this icon to hide all screenshots.

 

 

 

Left Curve
Popular Downloads
Right Curve
Untitled Document