Sie sind auf Seite 1von 3

TUNIS BUSINESS SCHOOL

UNIVERSITY OF TUNIS

Cursors and Exceptions’ handling

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:

The address of pilot FEDOI is: NANTES


The address of pilot ANDRE is: NICE
The address of pilot BAR is: LYON
The address of pilot MARTIN is: ORSAY

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.

3. Write a PL-SQL block that:


 Identify the list of pilots who have been assigned to only one flight. Use a cursor
C3.
 Insert this list of pilots to a table T1 whose content references to pilot.nopilot
table.
 For each pilot, insert the corresponding commission in a second table T2 whose
content references to pilot.comm table.
 Reduce each pilot commission with 5% and insert the result of each reduction in a
third table T3.

DBM (IT 300) 1


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

 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:

Names: Hiring Dates:


FEDOI 15/03/93
COLLET 15/04/93

B. Exceptions’ handling:

DBM (IT 300) 2


TUNIS BUSINESS SCHOOL
UNIVERSITY OF TUNIS

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.

DBM (IT 300) 3

Das könnte Ihnen auch gefallen