Solution 3
i. Demonstrate how you
a. Update the damage amount for the car with a specific Reg. no in the accident with report number12to 25000.
UPDATE PARTICIPATED SET DMG_AMT=25000 WHERE REPORTNO=12;
ii.Add a new accident to the database.
Insert into accident values(55,'02-jan-2002','bankapur');
iii.Find the total number of people who owned cars that were involved in accident sin 2002.
Select count(a.d_id) as num_of_accident from person a,participated pa,accident b where a.d_id=pa.d_id and b.reportno=pa.reportno and acc_date like '%02';
iv. Find the total number of accidents in which cars belonging to a specific model were involved.
Select count(p.reportno) as sum_of_accident from accident a,participated p,car c where a.reportno=p.reportno andp.regno=c.regno and model='toyota';
Write PL/SQL program demonstrate exception handling for the above query v.
v_model VARCHAR2(50) := 'Toyota'; -- Change model as needed
v_accident_count NUMBER;
BEGIN
-- Try to find the number of accidents for the specified car model
SELECT COUNT(DISTINCT P.reportno) INTO v_accident_count
FROM PARTICIPATED P
JOIN CAR C ON P.Regno = C.Regno
WHERE C.model = v_model;
IF v_accident_count = 0 THEN
DBMS_OUTPUT.PUT_LINE('No accidents found for the model: ' || v_model);
ELSE
DBMS_OUTPUT.PUT_LINE('Total accidents for model ' || v_model || ': ' || v_accident_count);
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found for the model: ' || v_model);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An unexpected error occurred.');
END;
/
Comments
Post a Comment