Update DBMS/SQL/Week6/writeup.md
This commit is contained in:
parent
8177218e4e
commit
a2d50a1f13
@ -26,24 +26,23 @@ TOTAL_ACCD(2024)
|
|||||||
|
|
||||||
### 2. Create a procedure to display total damage caused due to an accident for a particular driver on a specific year.
|
### 2. Create a procedure to display total damage caused due to an accident for a particular driver on a specific year.
|
||||||
```SQL
|
```SQL
|
||||||
create or replace procedure tot_damage
|
CREATE OR REPLACE PROCEDURE tot_damage
|
||||||
(driver in varchar2, year in number) is
|
(driver IN VARCHAR2, year IN NUMBER) IS
|
||||||
damage number := 0;
|
damage NUMBER := 0;
|
||||||
begin
|
BEGIN
|
||||||
select sum(damage_amount) into damage
|
SELECT NVL(SUM(pa.DAMAGE_AMOUNT), 0) INTO damage
|
||||||
from participated pa
|
FROM participated pa
|
||||||
natural join accident ac
|
JOIN accident ac ON pa.REPORT_NUMBER = ac.REPORT_NUMBER
|
||||||
where pa."driver_id#" = driver
|
WHERE pa.DRIVER_ID# = driver
|
||||||
with quotes
|
AND EXTRACT(YEAR FROM ac.ACCD_DATE) = year;
|
||||||
and extract(year from ac.accd_date) = year;
|
|
||||||
|
|
||||||
dbms_output.put_line('total damage: ' || nvl(damage, 0));
|
DBMS_OUTPUT.PUT_LINE('Total damage: ' || damage);
|
||||||
exception
|
EXCEPTION
|
||||||
when no_data_found then
|
WHEN NO_DATA_FOUND THEN
|
||||||
dbms_output.put_line('no data found for the given driver and year.');
|
DBMS_OUTPUT.PUT_LINE('No data found for the given driver and year.');
|
||||||
when others then
|
WHEN OTHERS THEN
|
||||||
dbms_output.put_line('an error occurred: ' || sqlerrm);
|
DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);
|
||||||
end;
|
END;
|
||||||
/
|
/
|
||||||
```
|
```
|
||||||
```sql
|
```sql
|
||||||
|
Loading…
x
Reference in New Issue
Block a user