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

Create your own function in Java that accepts one input parameter and returns a float number....
Create your own function in Java that accepts one input parameter and returns a float number. You decide the theme.
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.
1. Write a method called isPalindrome that accepts a string as a parameter and returns true...
1. Write a method called isPalindrome that accepts a string as a parameter and returns true if the string is a palindrome otherwise returns false. This method uses a stack and a Queue to test whether the given string parameter is a palindrome [ that is, whether the characters read the same both forward and backward. For example “race car”, and “Are we not drawn onward, to new era.” are Palindromes] They are palindrome sentences, not just a word. 2....
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...
Create a view that will display the student id, name, event id, category, and score for...
Create a view that will display the student id, name, event id, category, and score for all events for students who scored a 70 or below on any test. Call this view atriskstudents. a. What code did you write for this view? Insert the snip of the contents of the view SQL code here: b. Using this view, display those students who earned a score of 65 or greater. Insert your snip here *********************************************************************************************************************************************************** *********************************************************************************************************************************************************** CREATE DATABASE Class; #-- Using...
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 .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT