Write an sql statement that displays customer details

Assignment Help Database Management System
Reference no: EM13850522

Question 1

Write a function (called total_cost) that returns the total cost of an item after the tax has been added to the product. The function has two IN parameters Customer ID and Item ID and returns a number as a result of the function execution. If a Customer ID or Product ID or STATE does not exist in the relevant tables the function should return NULL as the result. You need to return the NULL result explicitly and not as a part of the cost calculation. The function calculates cost of an item based on the percentage charged for the state the customers address is in.

Write an SQL statement that displays customer details (ID, First Name, Last, Name, State) and total to be paid for each customer for product in the BB_PRODUCT table whose ID is 4 by calling the total_cost function.

Write a procedure (called report_on_products) that takes a single IN parameter Product ID and creates a report to the screen as follows. For every customer in the table create a report using the DBMS_OUTPUT module to print the Customer Last Name, First Name,

State, Product Description, Product Cost, Tax, total cost by calling the total_cost function.

After processing all the customers display the following information.

Total customers processed XX and total tax calculated $XX.YY.

The tax calculated is the sum of tax that each customer would have had to pay in that product.

Call the procedure from an anonymous block and capture the results.

Question 2

The Brewers Company is concerned about possible unauthorised changes to customer orders that may compromise the company's profit. You will create a database trigger to monitor such changes to some important columns in the BB_BASKET table.

1. Create a copy of the BB_BASKET table in your own schema by using the following command:

CREATE TABLE MY_CUSTOMER AS SELECT * FROM BB_BASKET;

2. Also create a table to store change logs (call the table BB_CHANGELOG) to hold the following fields IDBASKET, QUANTITY, SUBTOTAL, TOTAL and LOG_DATE DATE. You will need to refer to the relevant table for field types and sizes. The LOG_DATE field will contain the system date.


3. Create a database trigger with the following specification:

• fires AFTER an UPDATE on MY_CUSTOMER table.

• fires if there is any change to QUANTITY, SUBTOTAL or TOTAL columns of the MY_CUSTOMER table.

• fires for each row.

• inserts a first row: the affected IDBASKET column, the OLD values of the QUANTITY, SUBTOTAL and TOTAL columns and the current

date into the table BB_CHANGELOG.

• inserts a second row: the affected IDBASKET column, the NEW values of the QUANTITY, SUBTOTAL and TOTAL columns and the current date into the table BB_CHANGELOG.

4. Test the trigger with the following specification:

• Go ahead and make a change to MY_CUSTOMER table by issuing the following command:

UPDATE MY_CUSTOMER

SET QUANTITY = 13, TOTAL = 25000

WHERE IDBASKET = 13;

5. Now, select all rows from the BB_CHANGELOG table. This should display the OLD and NEW values of the changes you made due to firing of the trigger. Output all the rows of CUSTOMER_CHANGELOG table.

Question 3 (40 marks)

This question has a few section (procedures and functions) described. You are free to write helper procedures or functions but they will have to have high cohesion and low coupling (do one thing only and not be reliant on external values).

1) Create a PL/SQL procedure called shopping_month which has an in parameters for the year and the month. The procedure will display to the screen the following information for each basket created (DTCREATED) for that year/month. The information needs to be retrieved using an explicit cursor.

Basket BASKEID has a total of BASKET_TOTAL plus SHIPPING total cost of order BASKET_TOATL_PLUS_SHIPING

2) Write a function called total_shipping which takes in the date parameter and calculates the cost of shipping for all the baskets which have been created in that year/month.

3) Write a procedure called uncommitted_month which reports on all the baskets created but where the order has not been placed (ORDERPLACED) for all the baskets in the table. The output should be as follows.

Currently there are COUNT numbers of orders created but not finalized with a total of $AMOUNT.XX and shipping cost of $SHIPPING.XX.

4) Write a procedure called report_shopping_totals that will produce the following output in the format specified bellow. The procedure needs to use explicit cursor/s for each year starting with the oldest year and produces a summary of the shopping for that month.

The years and month output needs to be in ascending order.

Example dummy output only as a guideline. You will need to replace the uppercase fields with the necessary values

Year YYYY
January

Basket BASKEID has a total of BASKET_TOTAL plus SHIPPING total cost of order BASKET_TOATL_PLUS_SHIPING

Basket BASKEID has a total of BASKET_TOTAL plus SHIPPING total cost of order BASKET_TOATL_PLUS_SHIPING

Total Shipping for the month $SHIPPING.XX

March

Basket BASKEID has a total of BASKET_TOTAL plus SHIPPING total cost of order BASKET_TOATL_PLUS_SHIPING

Total Shipping for the month $SHIPPING.XX

Year YYYY

February

Basket BASKEID has a total of BASKET_TOTAL plus SHIPPING total cost of order BASKET_TOATL_PLUS_SHIPING

Total Shipping for the month $SHIPPING.XX


Total number of baskets processed COUNT total income of all orders is $AMOUNT.XX total shipping cost $SHIPPING.XX.

There are COUNT numbers of orders created but not finalized with a total of $AMOUNT.XX and shipping cost of $SHIPPING.XX.

The anonymous block should only have to call report_shopping_totals which will contain the logic to display the requested output. Your solution for the final output needs to use the functions and procedures defined previously. Due to the data in the tables you will only have one year on the report. Your code needs to work when more data is added.

Reference no: EM13850522

Questions Cloud

Explain the discrepancy : Explain the discrepancy
Write a c program for addition : Write a C Program for addition
What are the main types of strategic alliances : What are the main types of strategic alliances? Compare and contrast them. Describe the basic steps for a successful e-commerce strategy
Explain demand schedule and demand curve : Find mathematically and graphically the Equilibrium price and Quantity - Explain demand schedule and demand curve, and how they are related? Why does the demand curve slope downward?
Write an sql statement that displays customer details : Write an SQL statement that displays customer details
Analyse the situation using four different frames : Choose a health management problem which you are familiar with and briefly describe it, using appendices if necessary. Analyse the situation using four different frames of reference.
Locate and article in the business press : Locate and article in the business press or professional business publications that addresses one of the   learning objectives for the week. This article must have been published within the   past 12   months.  Write a one-paragraph summary of the ar..
Describe the types of employees in multinational firms : How do nations differ in HRM? What are the major national context characteristics that affect IHRM? Describe the types of employees in multinational firms. How does IHRM select and prepare them for international assignments
Develop a business idea into an original business plan : The goal of the final project for this course is to develop a business idea into an original business plan. To complete the business plan due in Week Five, you will be assigned a part of the process.

Reviews

Write a Review

Database Management System Questions & Answers

  Evaluate the reliability of the data mining algorithms

data mining the development of complex algorithms that can mine mounds of data that have been collected from people and

  Objectivesto analyse and comprehend a provided er diagram

objectivesto analyse and comprehend a provided er diagram and database schemato implement a database based on the

  Produce a distributed data design for enterprise

Produce a distributed data design for this enterprise. Show data fragmentation/partitioning and replication for each regional database location. Indicate what attributes are in each fragment

  Write sql select statements to retrieve

How many models of the Titanic have been shipped? What was the date of the first shipment and when was the last shipment sent - Write SQL SELECT statements to retrieve

  Explain why is hashing all database inputs not considered

question 1 what are the similarities between an md5 hash and a fingerprint?question 2 how would you encrypt a web

  Identify the potential sale and department store transaction

Evaluate whether the use of a distributed DBMS structure is appropriate and identify the optimization techniques that should be factored in to enhance the operations of the database in your design.

  In a database the primary key field is used to

In a database, the primary key field is used to

  Write down sql dml statements which address the given

write sql dml statements that address the following requirements 1 update the employees table and give all employees

  Develop view for sum of number ordered multiplied by price

Develop a view named OrdTot. It comprises the order number and order total for each order presently on file. (Order total is sum of the number ordered multiplied by quoted price.

  Draw at a context diagram and a level-0 diagram

Draw at a context diagram and a level-0 diagram. In drawing these diagrams, if you discover that the narrative is incomplete, make up reasonable explanations to complete the story. Provide these extra explanations along with the diagrams.

  Describe the importance of using sub queries in a database

1. Extracting and interpreting data can be very valuable to an organization. Describe the importance of using sub queries in a database system. Provide at least two business case scenarios to support your response.

  Open source relational database management system

Imagine you are a part of a team that is tasked with writing a mobile application (app) that will allow users to send pictures to their friends. The manager does not want to waste time creating code modules.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd