You are on page 1of 22

Manipulating Database Objects Using Oracle Application Express 4.

Page 1 of 22

Manipulating Database Objects Using Oracle Application Express 4.1


This tutorial contains the following sections: Purpose Time to Complete 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 Resources

Purpose
This tutorial shows you how to manipulate database objects using Oracle Application Express. Note: Some screenshots in this tutorial may be slightly different depending on what browser you use.

Time to Complete
Approximately 30 minutes.

Overview
What Is Oracle Application Express? Oracle Application Express is a hosted declarative development environment for developing and deploying databasecentric Web applications. Thanks to built-in features such as user interface themes, navigational controls, form handlers, and flexible reports, Oracle Application Express accelerates the application development process. 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 Team Development Administration 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. Used to access database objects, run SQL statements and SQL scripts. Facilitates the management of the application development process. Used to manage services and users and to monitor activity.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 2 of 22

Region

Item

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. 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 installs with your Oracle database and is comprised of data in tables and PL/SQL code. Oracle Application Express utilizes a Web browser on the user's computer communicating through a Web listener to the Oracle Database. No client software, other than a browser, is required for development, deployment or runtime as Application Express pages are rendered using HTML within the browser. Page requests and submissions are sent to the Application Express engine within the Oracle Database. When you create or extend an application, Oracle Application Express creates or modifies the meta data stored in its database tables. When the application is run, the Application Express engine then reads the meta data and displays the requested page or processes page submissions. To provide stateful behavior within an application, Oracle Application Express transparently manages session state in the database. Application developers can get and set session state using simple substitutions as well as standard SQL bind variable syntax. Apache MOD_PLSQL One way to access the Oracle Application Express engine is to configure the Oracle HTTP Server (Apache) containing the mod_plsql plug-in . The plugin functions as communication broker between the Web server and the Oracle Application Express objects in the Oracle database. This maps browser requests into database stored procedure calls. Images are stored on the file system and served by Apache. Using Apache allows the web listener to be placed on the same physical machine as the database, or on a separate physical machine. Embedded PL/SQL Gateway (EPG) The embedded PL/SQL gateway runs in the XML DB HTTP server in the Oracle database and includes the core features of mod_plsql, but does not require the Oracle HTTP Server powered by Apache. The EPG stores and serves all files, including images, CSS, and Javascript from the database. The EPG is convenient for smaller configurations. The EPG is not recommended for larger scale production use cases or Internet facing applications. Oracle Application Express Listener Oracle Application Express is a Java-based Web server. It features file system caching, support for FOP transformations to PDF, offers improved file upload capability, and is certified against Web Logic, Tomcat, and OC4J. The Oracle Application Express architecture requires some form of Web server to proxy requests between a Web browser and the Oracle Application Express engine. The APEX Listener was created to satisfy that need but its use goes beyond that of Application Express configurations. The use of the Oracle APEX listener simplifies the deployment process because there is no Oracle home required as connectivity is provided using an embedded JDBC driver. What is new in Oracle Application Express 4.1? The following is the summary of the new features in Oracle Application Express 4.1. Websheets Websheets enable any user to quickly build and deploy Web-based data entry and reporting applications. The Websheet application's interface has been extensively enhanced. Other enhancements include new page section types like PL/SQL, improved spreadsheets/data integration and page navigation, and the ability to define BLOB formats mask to report columns.

Improved Application Builder

The Application Builder includes new features like creating an application instantly, new API to redirect to an URL, ability to specify application date time formats, which provides default format for Calendar Dates, a hosted Online help and so on.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 3 of 22

Chart Enhancements In addition to added support for maps and Gantt charts, you can specify a label position, either outside or inside, for pie charts and doughnut charts. Dynamic Actions

You can declaratively create dynamic actions on buttons.

Enhanced Interactive Reports

Interactive reports now support additional functions in Interactive Report Computation / Row Filter Dialog along with icon and detail views, calendar views, inline edit, compound filter expressions, email notification, and a new group by functionality. Additionally, each report features enhanced Save options, can be downloaded to searchable HTML, and offers more granular printing capabilities.

Improved Error Application and Page Processes of processing point "On Submit - Before Computation and Validations" Handling and "On Submit - After Computations and Validations" have a new attribute called "Error Message Display Location" which allows developers to select "Inline in Notification" or "On Error Page" as error display location if a process fails. It has new Error Handling function which helps in modifying and log any error which occurs in Apex application. Plug-ins Plug-ins has been enhanced with new features like 'Escape special characters' flag to region attributes, 'Substitute Attribute Values' flag to plug-in configuration, add plug-in support for authorization schemes, increased number of custom attributes and new attribute type 'Checkboxes'. Use of ROWID Application Express allows usage of ROWID for Automatic DML processing by selecting ROWID as the primary key for a table or view when creating forms. This feature will allow developers to create forms and use the default DML processing on tables that do not have a natural primary key, as well as forms on views that do not expose the primary key. ROWID can be used for updates, inserts and deletes in tabular forms as an alternative to primary keys. It allows developers to choose a column to be used for lost update detection during create form and create form and report wizards.

Prerequisites
Before starting this tutorial, you should: Install Oracle Database 11g. Install Oracle Application Express 4.1. Download and unzip the files.zip file into a working directory to use during this tutorial.

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://localhost: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>

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 4 of 22

3.

To create the table, first you need to load the spreadsheet data. Click the down arrow next to SQL Workshop and then select Utilities > Data Workshop.

4.

Click Spreadsheet Data.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 5 of 22

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 Choose File.

7.

Locate the tasks.txt file in the directory where your files are located and click Open. Because the data in the text file is tab delimited, enter \t in the Separator field. Click Next .

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 6 of 22

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 Text Data Load Repository page. You can see the file that you just uploaded with 16 rows successfully uploaded. To view your new table, click the down arrow next to SQL Workshop tab and select Object Browser.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 7 of 22

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

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

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 8 of 22

13 . 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.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 9 of 22

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.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 10 of 22

3 . To specify the column on which the master table is to be created, select PROJECT - varchar2, and 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.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 11 of 22

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

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 12 of 22

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.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 13 of 22

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 ) on the left of PROJECT_ID for Public Website.

9 . For Project Deadline, enter a date greater than today's date. Enter 1 for Priority. Then click Apply Changes.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 14 of 22

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 icon.

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. You are in the SQL Scripts page. Click Upload.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 15 of 22

2.

Click Choose File.

3.

Select employees.sql from your working directory and click Open. Enter OBE_EMPLOYEES for the Script Name and click

4.

Click the Run icon.

5.

Click Run Now to confirm.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 16 of 22

6.

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

7.

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

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 . Click Object Browser.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 17 of 22

2 . Select the OBE_TASKS table.

3 . Click the Constraints tab.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 18 of 22

4 . Click Create.

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

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 19 of 22

6 . Click Finish.

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

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 20 of 22

8 . Click Create.

9 . Select PROJECT_PRIORITY for the Constraint on Column field and enter in ('1','2','3') for the Constraint Expression. Ensure that selected. Then click Next .

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 21 of 22

10 . Click Finish.

11 . The constraint was created successfully. Click the Home breadcrumb.

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011

Manipulating Database Objects Using Oracle Application Express 4.1

Page 22 of 22

Summary
In this tutorial, you have learned how to: Create a table from a spreadsheet Create a lookup table Modify a table Run a script to create a table Create a constraint in a table

Resources
Oracle Application Express homepage on OTN. Oracle Learning Library Oracle University

Copyright 2011, Oracle and/or its affiliates. All rights reserved

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r41/apexstart_a/ape...

12/30/2011