manipulating database objects using oracle application express 4

Upload: joel-bautista

Post on 07-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 Manipulating Database Objects Using Oracle Application Express 4

    1/7

    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 Us ing a ScriptAdding a Constraint

    Summary

    Resources

    Purpose

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

    Note: Some screenshots i n this tutorial may be s lightly different depending on what browser you use.

    Time to Complete

    Approximately 30 minutes.

    Overview

    What Is Oracle Application Express?

    Oracle Application Express is a hos ted declarative development environment for developing and deploying database-centric Web applications. Thanks to bui lt-in features such as userinterface 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 BuilderUsed to build database-centric interactive Web applications.

    SQL Workshop Used to access database objects, run SQL statements and SQL s cripts.

    Team Development Facilitates the m anagement of the application development process.

    Administration Used to m anage services and us ers and to monitor activity.

    Terminology

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

    WorkspaceA workspace is a virtual private database allowing multiple us ers to work within the s ame OracleApplication Express installation but keeping their objects, data and applications private.

    ApplicationAn application is a collection of pages with branches that connect them. Its attributes i nclude theauthentication method, default UI templates, and authorization rules.

    Page A page is the bas ic building block of an application. When you build an application in Application Builder,you create pages that contain user interface elements, such as tabs, l ists, buttons, items, and regions.

    Region Content is displayed in regions, which are logical s ubsections of a page. Each page can have anynumber 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 pos itionedon the page using di splay 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 thedisplay and behavior of items on a page. For example, these attributes can impact where a labeldisplays, how large an item is , and whether or not the item is displayed next to, or below the previousitem. The value of an item is automatically stored into the application's s essi on state, which can bereferenced at any point within the user's ses sion.

    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 us er's computer comm unicating through a Web lis tener to the Oracle Database. No client s oftware, other than a browser, isrequired for development, deployment or runtime as Application Express pages are rendered using HTML within the browser. Page requests and subm iss ions are sent to the ApplicationExpress 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 Expressengine then reads the meta data and displays the requested page or process es page s ubmiss ions.

    To provide s tateful behavior within an application, Oracle Application Express transparently manages ses sion state in the database. Application developers can get and s et ses sion s tate

    using s imple s ubstitutions as well as s tandard 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 i n the Oracle database. This maps browser requests into database stored procedure calls. Images are stored on the file

    system and s erved by Apache. Using Apache allows the web listener to be placed on the sam e physical machine as the database, or on a separate physical m achine.

    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 smal ler configurations. The EPG is not recommended

    for larger scale production use cas es or Internet facing applications.

  • 8/4/2019 Manipulating Database Objects Using Oracle Application Express 4

    2/7

    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 becaus e 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 s ummary of the new features in Oracle Application Express 4.1.

    WebsheetsWebsheets enable any user to quickly build and deploy Web-based data entry and reportingapplications. The Websheet application's interface has been extensively enhanced. Otherenhancements include new page section types like PL/SQL, improved s preadsheets/data integrationand page navigation, and the ability to define BLOB formats mask to report columns.

    ImprovedApplicationBuilder

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

    ChartEnhancements In addition to added support for maps and Gantt charts, you can specify a label position, either

    outside or ins ide, for pie charts and doughnut charts.

    DynamicActions You can declaratively create dynamic actions on buttons.

    EnhancedInteractiveReports

    Interactive reports now support additional functions in Interactive Report Computation / Row FilterDialog along with i con and detail views, calendar views, inline edit, compound filter express ions,email notification, and a new group by functionality. Additionally, each report features enhanced Saveoptions, can be downloaded to s earchable HTML, and offers more granular printing capabilities.

    Improved ErrorHandling Application and Page Processes of processing point "On Submit - Before Computation and

    Validations" and "On Submit - After Computations and Validations" have a new attribute called "ErrorMessage Dis play Location" which allows developers to select "Inline in Notification" or "On ErrorPage" as error display location if a process fails. It has new Error Handling function which helps inmodifying and log any error which occurs in Apex application.

    Plug-insPlug-ins has been enhanced with new features like 'Escape s pecial characters' flag to regionattributes, 'Substitute Attribute Values' flag to plug-in configuration, add plug-in support forauthorization schemes, increased number of custom attributes and new attribute type 'Checkboxes'.

    Use of ROWIDApplication Express allows usage of ROWID for Automatic DML processing by selecting ROWID asthe primary key for a table or view when creating forms. This feature will allow developers to createforms and use the default DML processing on tables that do not have a natural primary key, as wellas forms on views that do not expose the primary key. ROWID can be used for updates, inserts anddeletes in tabular forms as an alternative to primary keys. It allows developers to choose a column tobe us ed for los t update detection during create form and create form and report wizards.

    PrerequisitesBefore 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 to localhost, your specifichostname or apex.oracle.com).

    http://localhost:8080/apex

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

    Workspace:Username: Password:

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

  • 8/4/2019 Manipulating Database Objects Using Oracle Application Express 4

    3/7

    4 . Click Spreadsheet Data.

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

    6 . Click Choose File.

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

    8 . The Table Information page displays the columns i n 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 anew 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 filethat you just uploaded with 16 rows successfully uploaded. To view your new table, click the down arrow next to SQLWorkshop tab and select Object Browser.

    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.

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

    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.

  • 8/4/2019 Manipulating Database Objects Using Oracle Application Express 4

    4/7

    3 . To specify the column on which the mas ter table is to be created, select PROJECT - varchar2, and Next .

    4 . Enter the following values, and click Next.

    New Table Name: OBE_PROJECTSNew 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.

    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_DEADLINEType: DATE

    3 . Click Finish.

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

    5 . Enter the following values, and click Next .

    Add Column: PROJECT_PRIORITYType: NUMBER

    Precision: 1

    6 . Click Finish.

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

  • 8/4/2019 Manipulating Database Objects Using Oracle Application Express 4

    5/7

    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 forPublic Website.

    9 . For Project Deadline, enter a date greater than today's date. Enter1 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 Scriptsicon.

    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.

    2 . Click Choose File.

    3 . Select employees.sql from your working directory and click Open. EnterOBE_EMPLOYEES for the Script Name and click Upload.

    4 . Click the Run icon.

    5 . Click Run Now to confirm.

    6 . The script was executed. To view the results, click the ViewResults 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 as signed. Perform the following steps:

    1 . Click Object Browser.

  • 8/4/2019 Manipulating Database Objects Using Oracle Application Express 4

    6/7

    . e e c e _ a e.

    3 . Click the Constraints tab.

    4 . Click Create.

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

    6 . Click Finish.

    7 . 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 thedata is inserted or updated. SelectOBE_PROJECTS.

    8 . Click Create.

    9 . Select PROJECT_PRIORITY for the Constraint on Column field and enterin ('1','2','3') for the Constraint Express ion. Ensure that Check Constraint Type isselected. Then click Next .

    10 . Click Finish.

    11 . The constraint was created succes sfully. Click the Home breadcrumb.

    Summary

    In this tutorial, you have learned how to:

    Create a table from a s preadsheet

    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

  • 8/4/2019 Manipulating Database Objects Using Oracle Application Express 4

    7/7