Advanced Databases Report 2
Advanced Databases Report 2
Advanced Databases
Assignment 1
Nivad Ramdass
By submitting this assignment, I acknowledge that I have read and understood all the rules as
per the terms in the registration contract, in particular the assignment and assessment rules
in The IIE Assessment Strategy and Policy (IE009), the intellectual integrity and plagiarism
rules in the Intellectual Integrity and Property Rights Policy (IE023), as well as any rules
and regulations published in the student portal.
Plagiarism Statements
For this question, I wrote PL/SQL blocks using EXECUTE IMMEDIATE to drop existing tables if they existed. I
used exception handling to ensure no errors were raised if the tables were already dropped.
I created several tables including customer, employee, donator, donation, delivery, and invoice, then inserted sample
data into each. Additionally, I added donation_id and delivery_id columns to the invoice table to link it with the
donation and delivery tables, ensuring proper relationships between these entities.
Question 3: Dropping and Creating the Funding Table
I dropped the funding table (if it existed) using EXECUTE IMMEDIATE, and then created a new funding table with
an auto-incrementing funding_id. I inserted a row into the table to demonstrate its functionality.
In this question, I used a PL/SQL block with a FOR loop to query customer returns. The query joined the customer,
donation, and returns tables to display the customer's name, donation item, price, and reason for the return, using
DBMS_OUTPUT to display the information.
Question 5: Customer Deliveries
I wrote a PL/SQL block to display deliveries for a specific customer (Jack). The block retrieved the customer’s
name, employee handling the delivery, the donation item, and the delivery dates, along with the number of days
between dispatch and delivery. This information was output using DBMS_OUTPUT.
Question 6: Total Amount Spent by Each Customer
This PL/SQL block aggregated the total amount spent by each customer based on their donations. I grouped by the
customer's name and used SUM to calculate the total donation value, applying a rating system for customers based
on the amount they spent. The results were displayed using DBMS_OUTPUT.
Question 7.1: %TYPE Attribute Example
In this question, we used the %TYPE attribute to declare a variable of the same data type as the email column in the
customer table. We assigned a specific customer ID (Jack’s customer_id = 11011) and retrieved his email address
using a SELECT INTO query, then displayed it using DBMS_OUTPUT.
Here, we used the %ROWTYPE attribute to declare a record that mirrors the structure of a row from the customer
table. We retrieved all of Jack’s details (name, address, email, etc.) and displayed them using DBMS_OUTPUT.
This question involved creating a custom PL/SQL exception. We queried the total donations for a customer and
raised the custom no_donations_found exception if the customer had not made any donations. The exception was
handled with a DBMS_OUTPUT message indicating no donations were made.
Question 8: Customer Ratings and Amounts
We used a query to calculate the total amount spent by each customer on donations and applied a rating system
based on the total amount. The query included a CASE statement to assign star ratings and displayed the customer's
name, total amount spent, and their rating.