0% found this document useful (0 votes)
76 views

Cursors and Exceptions' Handling: A. Cursor

This document contains examples of PL/SQL code using cursors and handling exceptions. It provides 6 examples: 1) using a cursor to display pilot addresses where salary exceeds 2200, 2) using %ROWTYPE to display planes with over 25 hours above average, 3) using a cursor to insert pilots assigned to one flight into tables and reduce their commission by 5%, 4) displaying pilot names and hire dates using cursors or non-cursor sets where salary exceeds 1500 and commission is less than 20% of salary, 5) handling exceptions when displaying a pilot's data and checking for commission higher than salary or commission is null, and 6) handling exceptions when displaying pilot names where salary exceeds 15900 and commission is null or salary is

Uploaded by

Malék Crístô
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Cursors and Exceptions' Handling: A. Cursor

This document contains examples of PL/SQL code using cursors and handling exceptions. It provides 6 examples: 1) using a cursor to display pilot addresses where salary exceeds 2200, 2) using %ROWTYPE to display planes with over 25 hours above average, 3) using a cursor to insert pilots assigned to one flight into tables and reduce their commission by 5%, 4) displaying pilot names and hire dates using cursors or non-cursor sets where salary exceeds 1500 and commission is less than 20% of salary, 5) handling exceptions when displaying a pilot's data and checking for commission higher than salary or commission is null, and 6) handling exceptions when displaying pilot names where salary exceeds 15900 and commission is null or salary is

Uploaded by

Malék Crístô
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like