Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask DBMS Expert


Home >> DBMS

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.

DBMS, Programming

  • Category:- DBMS
  • Reference No.:- M91420298
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in DBMS

Query 1 the bookstore has decided to keep track of the

Query 1: The bookstore has decided to keep track of the vendors' information. In order to do this, one new table will be added to the database. The schema for this table, as related to the existing tables, is the followi ...

Instructionsfor decades relational databases remained

Instructions For decades, relational databases remained essentially unchanged; data was segmented into specific chunks for columns, slots, and repositories, also called structured data. However, in this Internet of Thing ...

Question find at least two academic sources that describe

Question: Find at least two academic sources that describe the movement of Enterprise resource planning (ERP) activities to the cloud. Discuss the types of ERP activities that can be conducted in the cloud and the pros a ...

In sql database questions phase-1 in 100 words what steps

In SQL Database Questions: Phase-1 In 100 words, what steps can one take to avoid losing work? Which command is used to save changes to the database? What is the syntax for this command? Phase-2 In 100 words, explain the ...

The case study company received a detailed report from the

The case study company received a detailed report from the ECM consultant with a detailed list of data requirements, tools, and processes that are currently used to manage this data. The chief executive officer (CEO) and ...

A taking an unnormalised list describe how you would

(a) Taking an unnormalised list, describe how you would normalise it using the normal forms technique and show how the result of this method is used. (b) You are currently in the process of developing a RDBMS for a natio ...

Case study problem 1 the case study company has experienced

Case Study: Problem 1 The case study company has experienced rapid growth in both the size of its client base and also in the services provided to clients. Unfortunately, the growth in data management policies, procedure ...

Your taskyou have been commissioned to develop a database

Your task You have been commissioned to develop a database system that is capable of keeping records for FU's table tennis matches from now on. The database needs to keep a record of: - All team information, including pl ...

Question team project submission - submit to the unit 4

Question: Team Project Submission - Submit to the Unit 4 Group Project Area This version of the capstone project assignment is FOR GRADING this week. Submit to the group area the document containing completed Sections On ...

Select from e d pwhere edeptddept and dcitypcity and

Select * From E, D, P WHERE E.dept=D.dept AND D.city=P.city AND D.budget>1M AND P.priority=A; Assuming relations have the same size and uniform distributions, what is the best plan with Nested Loop joins only? Write it a ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As