1administración de Database Objects Utilizando Application Express 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Administracin de Database Objects utilizando Application Express 4.

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

Prerequisites
Before starting this tutorial, you should:

Install Oracle Database 11g. Install Oracle Application Express 4.0. 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>

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.

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 .

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.

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 the table.

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

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 a date greater than 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 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.

2 . Click Choose File.

3 . Select employees.sql from your working directory and click Open. Enter OBE_EMPLOYEES for the Scr

4 . Click the Run icon.

5 . Click Run Now to confirm.

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 breadcr

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.

2 . Select the OBE_TASKS table.

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 O the Reference Table Name and select EMPLOYEE_ID from the Reference Table Column List. Then click

6 . Click Finish.

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

8 . Click Create.

9 . Select PROJECT_PRIORITY for the Constraint on Column field and enter in ('1','2','3') for the Constrai Check Constraint Type is selected. Then click Next .

10 . Click Finish.

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

You might also like