Write a script that creates and calls a stored procedure

Assignment Help PL-SQL Programming
Reference no: EM13679876

1. Write a script that creates and calls a stored procedure named spInsertProduct that inserts a row into the Products table. This stored procedure should accept five parameters. One parameter for each of these columns: CategoryID, ProductCode, ProductName, ListPrice, and DiscountPercent.

If the value for the ListPrice column is a negative number, the stored procedure should raise an error that indicates that this column doesn't accept negative numbers. Similarly, the procedure should raise an error if the value for the DiscountPercent column is a negative number.

When inserting data into the Products table, set the Description column to an empty string and set the DateAdded column to the current date.

Code at least two EXEC statements that test this procedure (one successful, one failure)

2. Write a script that creates and calls a stored procedure named spUpdateProductDiscount that updates the DiscountPercent column in the Products table. This procedure should have one parameter for the product ID and another for the discount percent.

If the value for the DiscountPercent column is a negative number, the stored procedure should raise an error that indicates that the value for this column must be a positive number.

Code at least two EXEC statements that test this procedure.

Trigger

3. Create a trigger named Products_INSERT that setsDateAdded column of the Products table to current date if the value for that column is null.

Test this trigger with the following
INSERT INTO Products (CategoryID, ProductCode, ProductName, Description, ListPrice, DiscountPercent) VALUES (1, 'G5122', 'Gretsch G5122 Double Cutaway Hollowbody', '', 999.99, 32);

Check and make sure the date was inserted with a SELECT statement.

4. Create a trigger named Products_UPDATE that checks the new value for the DiscountPercent column of the Products table. This trigger should raise an appropriate error if the discount percent is greater than 100 or less than 0.

If the new discount percent is between 0 and 1, this trigger should modify the new discount percent by multiplying it by 100. That way, a discount percent of .2 becomes 20.

Test this trigger with the following

UPDATE Products
SET DiscountPercent = .25
WHERE ProductID = 1;

Check to make sure the DiscountPercent is 25 with a SELECT statement.

Cursors

5. Write a script that creates a cursor for a SELECT query that consists of the ProductName and ListPrice columns for each product with a list price that's greater than $700. The rows in this result set should be sorted in descending sequence by list price. Then, the script should print the product name and list price for each product so it looks something like this:

Gibson SG, $2517.00

Gibson Les Paul, $1199.00

6. Write a script to declare and use a cursor for the following SELECT statement. Use a WHILE loop to fetch each row in the result set. Fetch each row into a set of local variables. Use the PRINT statement to return each row in the format "Name, $0.00" to the Messages tab.

SELECT LastName, AVG(ShipAmount) AS ShipAmountAvg

FROM Customers JOIN Orders

    ON Customers.CustomerID = Orders.CustomerID

GROUP BY LastName;

Reference no: EM13679876

Questions Cloud

Comment on michael and susan approaches : Comment on Michael and Susan approaches
Company date acquired cost date sold sales price : Company Date acquired Cost Date sold Sales price
Account titles and explanation : Account Titles and Explanation
Identify and describe the cash-based liquidity measures : Identify and describe the cash-based liquidity measures.
Write a script that creates and calls a stored procedure : Write a script that creates and calls a stored procedure named spInsertProduct that inserts a row into the Products table. This stored procedure should accept five parameters.
Theta counters clockwise from the left direction : A proton is traveling horizontally to the right at 4.20×10^6 m/s . Discover (a) the magnitude and (b) direction of the weakest electric field that can bring the proton uniformly to rest over a distance of 3.10cm.
Is an award of monetary damages an adequate remedy : What is the likelihood that the daughter's suit will succeed? State your reasons. Is contract rescission a potential remedy? Why or why not? Is an award of monetary damages an adequate remedy? Why or why not?
Glasier health products : Glasier Health Products
Impact the productivity of an organization : Explore how individual differences, personality traits, and perspectives impact the productivity of an organization - review learning theories and their relationship to organizational performance

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Pretend that you are on the boards

Pretend that you are on the boards of the American National Standards Institute (ANSI) and the International Organization for Standards (ISO), two of the organizations who standardized SQL

  If the value for the listprice column is a negative number

If the value for the ListPrice column is a negative number, the stored procedure should raise an error that indicates that this column doesn't accept negative numbers. Similarly, the procedure should raise an error if the value for the DiscountPer..

  Construct a query that will show the number of days

Imagine that you work for a finance industry-based organization. Your organization is looking to submit its database design documentation to an evaluation team in order to meet Sarbanes-Oxley (SOX) compliance.

  Create a database model

Create a database model and Submit the table creation statements for the Database Model.

  Write sql queries

Write a query to display the last name, department number, and salary of any employee whose department number and salary both match the department number and salary of any employee who earns a commission.

  Write a script that declares a variable

Write a script that declares a variable and sets it to the count of all products in the Products table. If the count is greater than or equal to 7, the script should display a message that says,

  Decomposition for r = (a,b,c,d,e )

Give a good decomposition for R = (A,B,C,D,E ) with the following functional dependencies:

  Provide four queries to answer questions asked by end users

Explain how you will go about developing this database. Provide at least four queries that answer some of the questions asked by the end users.

  Create tables using sql ddl

Write the SQL DDL to create the database that contains each of the relations shown in the above ERD. You will need to provide - Your DDL code for each table that you create and a screenshot showing each table that is created.

  Question 1write a perl subroutine for temperature

question 1write a perl subroutine for temperature conversion named converttemp. it should be able to handle both

  Table called transactionlog

Create a table called TransactionLog. Create a trigger, which inserts a new record (user CardNo, ISBN, date) into the TransactionLog table whenever the a borrower checks out a book or returns a book.

  Write a script that uses two variables

Write a script that uses two variables to store (1) the count of all of the products in the Products table and (2) the average list price for those products. If the product count is greater than or equal to

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