Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

GCIS_5160A_Data Centric Concepts_Assignment-4

Student Name: Karthik Bala Manokaran


Student ID : 3138610
Department: CIS-Data Science-21SP
Considerations:
Assignment 4-5 Performing exception handling of predefined errors.
A block of code has been created to retrieve basic customer information and can be
found in the assignment04-05.txt in the Chapter.04 folder. The application screen
was modified so that an employee can directly enter a customer number that could
potentially cause an error An appropriate exception handler needs to be added to
the block The handler should display a message to the screen that states 'Invalid
shopper Id' Use a host variable named G_SHOPPER to provide a shopper id. Test the
block with a shopper id of 99.

Assignment 4-6 Performing exception handling of non-predefined errors.


Brew bean’s wants to add a check constraint on the quantity column of the BB
BASKETITEM table. If a quantity value provided by a shopper on an item is greater
than 20, Brew beans wants to display a message saying, "Check Quantity". The file
named assignment04-06.txt can be found in the Chapter.04 folder. The first
statement is an ALTER TABLE statement that needs to be executed to add the check
constraint. The next item is a PL/SQL block containing an insert that tests this check
constraint. Add the appropriate code to the block to trap the check constraint
violation and display the desired message.

Assignment 4-7 Performing exception handling with user-defined errors.


On occasion. some of Brew bean’s customers mistakenly leave an item out of a
basket already checked out, so they create a new basket containing the missing
items. However, they request that the baskets be combined so that they are not
charged extra shipping. A screen has been developed to allow an employee to
modify the basket id of Items in the BB_BASKETITEM table to another existing basket
to combine the baskets. A block has been constructed to support this screen and can
be found as file assignment04-07.txt In the Chapter.04 folder. However, an
exception handler needs to be added to trap the situation in which an invalid basket
Id Is entered for the original basket. In this case, the UPDATE affects no rows but
does not raise an Oracle error The handler should display a message stating "Invalid
original basket id". Use a host variable named G_OLD with a value of 30 and a host
variable named G_NEW with a value of 4 to provide the values to the block. First,
verify that no item rows exist in the BB BASKETITEM table with a basket id of 30.
GCIS_5160A_Data Centric Concepts_Assignment-4

Assignment 4-8 Processing and update a group of rows.


To assist in tracking employee information, a new employee table was added to the
Brew bean’s database. Review the data In the EMPLOYEE table. A PL/SQL block Is
needed to calculate annual raises and update employee salary amounts recorded in
the table Create a block that addresses all the requirements listed below. Note that
all salaries in EMPLOYEE table are recorded as monthly amounts. Tip: Display the
calculated salaries for verification before including the update action.

• Calculate 6% annual raises for all employees except the president.


• If 6% totals to more than $2,000, cap the raise at $2,000.
• Update the salary for each employee in the table.
• For each empno, display the current annual salary, raise, and proposed new annual
salary.
• At the end, show the total amount of annual salary increase.

Assignment 4-5 Performing exception handling of predefined errors.

Input:
--KarthikBala--
var g_shopper Number;
Begin
:g_shopper:=99;
End;
DECLARE
lv_tot_num bb_basket.total%TYPE;
BEGIN
SELECT total
INTO lv_tot_num
FROM bb_basket
WHERE idshopper = :g_shopper;
Exception
when NO_DATA_FOUND then
dbms_output.put_line('Invalid Shopper ID');
End;
/
GCIS_5160A_Data Centric Concepts_Assignment-4

Output:
Invalid Shopper ID

Input:
--Karthik Bala--
ALTER TABLE bb_basketitem
ADD CONSTRAINT bbitems_qty_chk CHECK (quantity<20);

DECLARE
ex_bitems_ck EXCEPTION;
PRAGMA EXCEPTION_INIT(ex_bitems_ck, -2290);
BEGIN
INSERT INTO bb_basketitem
VALUES (78,7,6,22,16,2,3);
EXCEPTION
WHEN ex_bitems_ck THEN
DBMS_OUTPUT.PUT_LINE('Check Quantity');
END;
/
GCIS_5160A_Data Centric Concepts_Assignment-4

Output:
Table BB_BASKETITEM altered.

Check Quantity.

Input:

--Karthik Bala--
var g_old number;
var g_new number;
Begin
:g_old:=30;
:g_new:=4;
End;
Declare
ex_id_fk EXCEPTION;
PRAGMA EXCEPTION_INIT(ex_id_fk, -02291);
BEGIN
UPDATE
bb_basketitem
SET
idBasket = :g_old WHERE idBasket = :g_new;
EXCEPTION
WHEN ex_id_fk THEN
DBMS_OUTPUT.PUT_LINE('Invalid original basket ID');
GCIS_5160A_Data Centric Concepts_Assignment-4

END;
/

Output:

Invalid original basket ID

Input:
---Karthik Bala---
/*CREATE TABLE employee(EMPLOYEE_ID NUMBER(4),ENAME VARCHAR2(10),JOB
VARCHAR2(9),SALARY NUMBER(7,2));
INSERT INTO employee VALUES (12,'Karthik','Developer',1000);
INSERT INTO employee VALUES (15,'Bala','President',3000);*/

DECLARE
CURSOR c_emp IS
SELECT * FROM employee;
inc_salary NUMBER(7,2);
total_cost_inc_ NUMBER(13,2):=0;
BEGIN
FOR c2 IN c_emp LOOP inc_salary:=0;
IF(c2.Job ='President') THEN
inc_salary:=0;
ELSE
inc_salary:=least(2000,round(c2.salary*6/100,2));
END IF;
GCIS_5160A_Data Centric Concepts_Assignment-4

total_cost_inc_:= total_cost_inc_+inc_salary;
dbms_output.put_line('New Salary for Employee: '||c2.employee_id||'-'||
c2.ename||' is');
dbms_output.put_line(nvl(c2.salary,0)+nvl(inc_salary,0));
UPDATE employee SET salary=salary+inc_salary
WHERE employee_id=c2.employee_id;
dbms_output.put_line('Details for Empno:'||c2.employee_id);
dbms_output.put_line('Name:'||c2.ename||' Job:'||c2.Job);
dbms_output.put_line('Current annual Salary:'||c2.salary*12);
dbms_output.put_line('Monthly raise:'||inc_salary);
dbms_output.put_line('Annual raise:'||inc_salary*12);
dbms_output.put_line('New Annual Salary: '||
(nvl(c2.salary,0)+nvl(inc_salary,0))*12);
END LOOP;
dbms_output.put_line('Total Cost of All employees salary is:'||total_cost_inc_*12);
COMMIT;
END;
/

Output:
New Salary for Employee: 12-Karthik is
1338.23
Details for Empno:12
Name:Karthik Job:Developer
Current annual Salary:15149.76
Monthly raise:75.75
Annual raise:909
GCIS_5160A_Data Centric Concepts_Assignment-4

New Annual Salary: 16058.76


New Salary for Employee: 15-Bala is
3000
Details for Empno:15
Name:Bala Job:President
Current annual Salary:36000
Monthly raise:0
Annual raise:0
New Annual Salary: 36000
Total Cost of All employees salary is:909

You might also like