Professional Documents
Culture Documents
Regulations
Attendance is mandatory
Every student should have his own laptop on which:
o Oracle XE and SQL Developer are mounted and working correctly
o A user account is created and has a copy of HR schema
Each PL/SQL LAB Session is followed by a 15 mn quiz on paper; the grade of the quiz will
be part of the lab final grade.
1
Non Oracle Error numbers are defined between -20,000 and -20,999.
BEGIN
3. Write a trigger to write the following details into job history: Employee ID, old job
ID, old department ID, hire date of the employee for start date, system date for end
date, whenever the job is changed for an employee. But if a row is already present
for employee job history then the start date should be the end date of that row +1.
create or replace trigger job_log_change
after update of job_id
on employees
for each row
declare
v_enddate DATE;
v_startdate DATE;
BEGIN
SELECT max(end_date) into v_enddate FROM job_history WHERE
employee_id = :old.employee_id;
IF v_enddate IS NULL THEN
v_startdate := :old.hire_date;
ELSE
v_startdate := v_enddate + 1;
END IF;
insert into job_history values (:old.employee_id, v_startdate,
sysdate, :old.job_id, :old.department_id);
END;
To test the trigger when job_history.enddate is NULL, we have to modify the not null constraint
(click on job_history then edit/properties).