Question

In: Computer Science

Oracle - Create a procedure that accepts product ID as a parameter and returns the name...

Oracle -

  1. Create a procedure that accepts product ID as a parameter and returns the name of the product from ProductTable table. Add exception handling to catch if product ID is not in the table.

Table to use:

CREATE TABLE ProductTable(

    ProductID INTEGER NOT NULL primary key,

    ProductName VARCHAR(50) NOT NULL,

    ListPrice NUMBER(10,2),

    Category INTEGER NOT NULL

);

/

INSERT INTO ProductTable VALUES(299,'Chest',99.99,10);

INSERT INTO ProductTable VALUES(300,'Wave Cruiser',49.99,11);

INSERT INTO ProductTable VALUES(301,'Megaland Play Tent',59.99,11);

INSERT INTO ProductTable VALUES(302,'Wind-Up Water Swimmers',2.00,11);

INSERT INTO ProductTable VALUES(303,'Garmin Pocket or Vehicle GPS Navigator',609.99,12);

Solutions

Expert Solution

Database Used :Oracle Live SQL.

Stored Procedure :

CREATE OR REPLACE PROCEDURE getProduct(
prodID IN ProductTable.ProductID%type,
ProdName OUT ProductTable.ProductName%type)
AS
BEGIN
SELECT ProductName INTO ProdName FROM ProductTable WHERE ProductID=prodID;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('Enter valid product ID');
END;
/

Executing stored procedure :

declare
ProductName varchar(50);
begin
getProduct(303, ProductName);
dbms_output.put_line(ProductName);
end;
/

Screen in Oracle Live SQL when product id is valid  :

Screen in Oracle Live SQL when product id is invalid  :


Related Solutions

Write a method sumTo that accepts an integer parameter n and returns the sum of the...
Write a method sumTo that accepts an integer parameter n and returns the sum of the first n reciprocals. In other words: sumTo(n) returns: 1 + 1/2 + 1/3 + 1/4 + ... + 1/n For example, the call of sumTo(2) should return 1.5. The method should return 0.0 if passed the value 0 and should print an error message and return -1 if passed a value less than 0. Include a loop. Please help for Java programming.
On Python Write a function that accepts a relative file path as parameter and returns number...
On Python Write a function that accepts a relative file path as parameter and returns number of non-empty lines in the file. Test your function with the provided sample file studentdata.txt.
Product(p-id, p-name, weight) Retailer(r-id, r-name, city) Sells(r-id, p-id, price)
  Product(p-id, p-name, weight)Retailer(r-id, r-name, city)Sells(r-id, p-id, price) r-id is a foreign key referencing Retailerp-id is a foreign key referencing Product Give a Relational Algebra expression : (IT IS NOT SQL) (a) Find the names of the retailers who are selling the products that have a weight greater than 10 kg.(b) Find the names of the retailers who have never sold a product that has a weight greater than 10 kg.(c) Get the price of the products that have a...
a.A method that accepts no parameters and returns the length of the name, i.e., the sum...
a.A method that accepts no parameters and returns the length of the name, i.e., the sum of the lengths of the three parts of the name. b.A method that accepts no parameters and returns a String consisting of the three initials IN UPPERCASE. c.A method that accepts an integer n and returns the nth character in the full three part name. d.A method that accepts no parameters and returns a String consisting of the last name followed by a comma...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person’s contact information. If the person is not found, the function returns, “name not in contact”. Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples:               contacts = “Frank...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both...
Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person’s contact information. If the person is not found, the function returns, “name not in contact”. Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples:               contacts = “Frank...
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
Create a view named ReservationCustomer_VW. It consists of the reservation ID, trip ID, trip name, trip...
Create a view named ReservationCustomer_VW. It consists of the reservation ID, trip ID, trip name, trip date, customer number, customer last name, customer first name, and phone number for trips whose guide is Glory Unser or Susan Kiley. Show the SQL Server code for this view.
PYTHON. Create a function that accepts a filename where in each line there is a name...
PYTHON. Create a function that accepts a filename where in each line there is a name of a type of bird. use a python dictionary in order to count the # of time each bird appears. (1 line = 1 appearance) Loop over your dict. to print each species and the # of times it was seen in the file once all lines have been counted. return dictionary containing count the filename opens this: blackbird canary hummingbird canary hummingbird canary...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for all product whose name includes both the words "silver" and "frame"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT