Cursors and Exceptions' Handling: A. Cursor
Cursors and Exceptions' Handling: A. Cursor
UNIVERSITY OF TUNIS
A. Cursor
1. Write a PL / SQL block that displays names and addresses of pilots whose salary
exceeds 2200. The result will appear as follows:
2. Write a PL-SQL block to display all information about planes with more than 25 hours
of flying higher comparing to the average of nbhflight of all existing planes. Use the
'% ROWTYPE' command. The result will appear as follows:
Plane Number: 8832, Type: 734, Year of Commission: 1988, Plane Name: City of Paris,
Total flight hours: 16000.
Plane Number: 7693, Type: 741, Year of Commission: 1988, Plane Name: Pacific,
Total flight hours: 34000.
Display the contents of the three tables T1, T2 and T3. The result will appear as
follows:
List of pilots:
1- 1333
2- 6589
3- 7100
4- 3452
5- 3421
6- 6548
List of commission before discount:
1- 0
2- 5580
3- 16000
4-
5-
6- 8600
List of commission after discount:
1- 0
2- 5301
3- 15200
4-
5-
6- 8170
4. Write-PL-SQL block to display the names of the pilots whose salary exceed 1500 and
the commission is less than 20% of salary. Display names of pilots and their hiring
dates. Propose two solutions: one using a non-cursor set and the second set using a
cursor. The result will appear as follows:
B. Exceptions’ handling:
5. Write a PL-SQL block to display the name, address, salary and the commission of pilot
number 1700.
Use the predefined oracle exception NO_DATA_FOUND.
If (commission > salary), raise an exception and display the following error
message: "The commission is higher than the salary"
If (commission = NULL), raise an exception and display the following error
message: "Commission is Null".
Run your PL/SQL block with the following pilots’ number: '1333', '3452', '7100'
and '5555'. In each case check the exception raised.
6. Write a PL-SQL block to display the names of the pilots whose salary exceed 15900.
If the condition is checked, the driver name will be automatically displayed.
If the (commission = NULL), an exception is triggered automatically displaying
the message 'the Commission of pilot ......... .. is Null'.
If (salary> 30000) excep_trait is triggered allowing to insert the name and
salary of the pilot in a PL/SQL Pilot_sal table.