Professional Documents
Culture Documents
Oracle 1 PDF
Oracle 1 PDF
This assignment provides experience with creating database tables, stored procedures and
triggers in Oracle database server. It also provides experience with creating simple web-based
database application using Oracle application express.
There are three parts in this assignment, and the marks distributions are
Assignment Submission:
You are going to submit a single ZIP file containing your answers of this
assignment via LearnJCU.
You need to name each script following the guidelines in each task
You need to name the ZIP file with your student number.
You need to make sure that each script can run successfully without syntax
error
Scripts with any syntax error will NOT be marked
Submissions deviate from the naming and submission guidelines
mentioned above will NOT be marked
1 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
You are going to create the database tables for the Expense Reporting database at ABCorp,
an IT consulting company. The Expense Reporting database contains tables to track users and
expenses reports, along with tables to track expense categories. The managers of the
company can use the database to understand the financial conditions of the company.
Task 1A (5pts)
You will need to create a database schema called ERDB to store all the database objects for
this assignment. You also need to grant the appropriate privileges to the ERDB users for
creating the database objects. You need to follow the principle of least privilege when
granting privileges.
Hint:
You may want to grant additional privileges to the user when you are working on PART2 of
this assignment. So, you may come back to this part again and include additional GRANT
statements. Make sure that the submitted script includes all the required GRANT statements.
SUBMISSION:
A script called PART1a.sql which contains SQL statement(s) for
creating the ERDB user
granting appropriate privileges to the ERDB user
Task 1B (20pts)
You need to use JDeveloper to create the entity relationship diagram (ERD) and to generate
the Data Definition Language (DDL) for creating the tables and constraints specified below.
You should use the table and column names as shown in Table 1 to 9.
2 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
3 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
4 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
You should choose appropriate actions when referenced rows are deleted. When an
expense report is deleted, both the heading row in the ExpenseReport table and the associated
detail rows in the ExpenseItem table should be deleted. For other referential integrity
constraints involving required foreign keys (nulls not allowed), deleting a referenced row in a
parent table should not be permitted if there are associated referencing rows in a child table.
For referential integrity constraints involving optional foreign keys (nulls allowed) except
ExpenseReport.ApprUserNo, deleting a referenced row should make the foreign key of the
referencing row null. For ExpenseReport.ApprUserNo, you should restrict deletion of related
User rows.
Define the following check constraints or unique constraind in the related tables.
• Email contains an @
• ERStatusDate >= ERSubmitDate
• BIYear>=1900
• ERStatus is ‘PENDING’ ‘APPROVED’, or ‘DENIED’
• ExpApprAmt <= ExpAmt
• The combination of BIYear, OrgNo, and ECNo is unique in the BudgetItem
table.
• Nulls are allowed for ExpenseReport.ApprUserNo only if ERStatus is equal to
PENDING
SUBMISSION:
A script called PART1b.sql generated by JDeveloper which contains SQL
statement(s) for
creating the required database tables and constraints
You should use the files (in data.zip) provided to construct INSERT statements to load the
data into the tables. You need to create a sequence generator for table to facilitate the auto
generation of primary key values. The INSERT statements should make use of the sequence
generators. The script InsertBlob.sql provided in LearnJCU shows an example of inserting
Blob data into the table. You also need to create a database user account for each user found
in the USER table. These users can submit expense reports; however, they cannot delete any
data.
SUBMISSION:
A script called PART1c.sql which contains SQL statement(s) for
creating the required sequence generators
inserting data into the tables
creating the database users accounts and granting appropriate privileges
5 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
Part 2: Creating Stored Procedures and Triggers using PL/SQL (total : 70pts)
You should write SQL and PL/SQL to define the triggers and stored procedure as specified in
the following subsections. You should also include SQL statements to test the triggers. Make
sure that you test single row as well as multiple row actions. Include comments for each
testing statement to indicate the trigger in which it applies and the expected results of the
trigger firing.
You should create a trigger called TR_ExceedingLimitNotice. This trigger fires after
inserting a row in the ExpenseItem table or updating the expense amount (ExpAmt). The
trigger body compares the expense amount to the category limit (ECLimit) in the related row
of the ExpCat table. If the expense amount is greater than the category limit, insert a row into
the exception log table (Log_Table).
SUBMISSION:
A script called PART2a.sql which contains SQL or PL/SQL for
creating the required trigger
inserting data into the table for testing trigger
showing the testing results, e.g. SELECT statement against the Log_Table
SUBMISSION:
A script called PART2b.sql which contains SQL or PL/SQL for
creating the required trigger
update data of the table for testing trigger
You should create a trigger called TR_ChangeStatusCase. This trigger fires before
inserting an ExpenseReport row or updating the expense report status (ERStatus). The body
of the trigger should change the case of the ERStatus column to upper case. You can use the
Oracle UPPER function in the trigger body.
SUBMISSION:
A script called PART2c.sql which contains SQL or PL/SQL for
creating the required trigger
inserting data of the table for testing trigger
showing the testing results
6 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
SUBMISSION:
A script called PART2d.sql which contains SQL or PL/SQL for
creating the required trigger
inserting and updating data of the table for testing trigger
You should create a stored procedure called spRollupExpenseItem. This procedure updates
the related row in the BudgetItem table given an expense report number and expense category
number. The procedure contains three input parameters, the ERNo value, the ECNo value,
and the rollup amount, along with one Boolean output parameter.
• Else, the related BudgetItem row is updated. The actual amount (BIActual) in the
related BudgetItem row are incremented by the rollup amount input parameter.
SUBMISSION:
A script called PART2e.sql which contains SQL or PL/SQL for
creating the required stored procedure
7 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
You should create a trigger called TR_RollupExpAmt. This trigger fires after updating the
expense approved amount (ExpApprAmt) or deleting a row of the ExpenseItem table. The
following points explain the logic of this trigger:
• If updating the ExpApprAmt column, the rollup amount should be the difference
of the New.ExpApprAmt minus the Old.ExpApprAmt.
• If deleting a row of the ExpenseItem table, the rollup amount should be the
negative of the Old.ExpApprAmt.
o The ExcText (message explaining the error) value should indicate the
operation (update or delete) and the rollup amount.
SUBMISSION:
A script called PART2f.sql which contains SQL or PL/SQL for
creating the required trigger
updating data in the table for testing the trigger
deleting data in the table for testing the trigger
showing the testing results, e.g. SELECT statements against the
Log_Table and the BudgetItem Table
8 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
9 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
Task 3b Create Pages for Add/Delete/Update Expense Report and Expense Item (30pts)
When the user clicks the “Create” button on the Expense Report page, it will display the form
below. This form allows user to enter new record. Notice that you should use include features
such as List of values to facilitate user input. You will also need to modify the label of the
items to show meaning description.
10 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
This is the screenshot for the edit expense report page. Related expense items are shown, and
user is allowed to edit or add expense items.
11 / 12
CP2503 Enterprise Database Systems - Oracle
Assignment 1 Due: 9 Oct 2008, 5pm (CP2503: 20%, CP5503:15%)
SUBMISSION:
• A script called PART3.sql which contains script exported from Oracle Application
Express for Task3a and Task3b.
12 / 12