Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* pilot_age is another function that has been created and tested and works, It displays the age of the employee from aa_employee table. This new function is supposed to take in that value and use it here*/
- CREATE OR REPLACE FUNCTION new_pilot
- (sf_emp_num IN NUMBER,
- pilot_age IN NUMBER)
- RETURN VARCHAR2
- IS
- CURSOR cur_pilot2 IS
- SELECT emp_num , emp_fname,PIL_MED_TYPE, TRUNC(MONTHS_BETWEEN(SYSDATE,PIL_MED_DATE)) LastPhys
- FROM aa_pilot INNER JOIN aa_employee
- USING(emp_num)
- WHERE sf_emp_num = EMP_NUM;
- lv_Status VARCHAR2(60);
- ex_notPilot EXCEPTION;
- BEGIN
- FOR rec_pilot2 IN cur_pilot2 LOOP
- IF cur_pilot2%NOTFOUND THEN
- RAISE ex_notPilot;
- ELSIF pilot_age < 40 AND rec_pilot2.LastPhys < 60 AND rec_pilot2.PIL_MED_TYPE = 3
- THEN lv_Status := 'Third Class Physical is Valid';
- ELSIF pilot_age > 40 AND rec_pilot2.LastPhys > 24 AND rec_pilot2.PIL_MED_TYPE = 3
- THEN lv_Status := 'Third Class Physical is Expired';
- ELSIF rec_pilot2.PIL_MED_TYPE = 2 AND rec_pilot2.LastPhys > 12
- THEN lv_Status := 'Second Class Physical is Expired';
- ELSIF pilot_age < 40 AND rec_pilot2.LastPhys > 12 AND rec_pilot2.PIL_MED_TYPE = 1
- THEN lv_Status := 'First Class Physical is Expired';
- ELSIF pilot_age > 40 AND rec_pilot2.LastPhys > 6 AND rec_pilot2.PIL_MED_TYPE = 1
- THEN lv_Status := 'First Class Physical is Expired';
- ELSE
- lv_Status := 'Does not need a Physical';
- END IF;
- RETURN lv_Status;
- END LOOP;
- EXCEPTION WHEN ex_notPilot THEN
- DBMS_OUTPUT.PUT_LINE('Not a pilot');
- END;
- /*call to the function using a select statement. Code works with all other employees that exist (101,104,105,106,109) on the aa_pilot table. I want the code to display a not a pilot message when calling upon employee 102 because that emp_num does not exist in the aa_pilot table */
- --This select statements call upon emp_num 101 and displays correct message
- SELECT emp_title || ' ' || emp_fname || ' ' || emp_lname || ' ' ||
- new_pilot(emp_num, pilot_age(emp_num)) "Physical" FROM aa_employee WHERE emp_num = 101;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement