Update DBMS/SQL/Week6/writeup.md
This commit is contained in:
		
							parent
							
								
									90db880472
								
							
						
					
					
						commit
						78565b88cb
					
				
					 1 changed files with 27 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -72,5 +72,32 @@ Report Number: 1, Date: 01-JAN-24, Location: Delhi India
 | 
			
		|||
PL/SQL procedure successfully completed.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 4. Create a procedure to identify all drivers who have never been involved in any accidents. The procedure should return their driver-id, name, and address.
 | 
			
		||||
 | 
			
		||||
```SQL
 | 
			
		||||
SQL> CREATE OR REPLACE PROCEDURE GetDriversWithoutAccidents AS
 | 
			
		||||
  2  BEGIN
 | 
			
		||||
  3      FOR rec IN (
 | 
			
		||||
  4          SELECT p.DRIVER_ID#, p.NAME, p.ADDRESS
 | 
			
		||||
  5          FROM person p
 | 
			
		||||
  6          LEFT JOIN participated pa ON p.DRIVER_ID# = pa.DRIVER_ID#
 | 
			
		||||
  7          WHERE pa.REPORT_NUMBER IS NULL
 | 
			
		||||
  8      ) LOOP
 | 
			
		||||
  9          DBMS_OUTPUT.PUT_LINE('Driver ID: ' || rec.DRIVER_ID# ||
 | 
			
		||||
 | 
			
		||||
 10                               ', Name: ' || rec.NAME ||
 | 
			
		||||
 11                               ', Address: ' || rec.ADDRESS);
 | 
			
		||||
 12      END LOOP;
 | 
			
		||||
 13  END;
 | 
			
		||||
 14  /
 | 
			
		||||
 | 
			
		||||
Procedure created.
 | 
			
		||||
```
 | 
			
		||||
```SQL
 | 
			
		||||
SQL> EXEC GetDriversWithoutAccidents;
 | 
			
		||||
Driver ID: 1237, Name: Saarthak, Address: Manipal India
 | 
			
		||||
Driver ID: 1235, Name: Rohit, Address: Banglalore India
 | 
			
		||||
 | 
			
		||||
PL/SQL procedure successfully completed.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue