-- Listing 7-10. Revising the Update Code of Listing 7-4
declare
    v_newjob  varchar2(9);
    v_newsal  number(7,2);
    v_newdept number(4,0);
begin
    -- First re-read the data.
    select Job, Sal, DeptNo
    into v_newjob, v_newsal, v_newdept
    from EMP
    where EmpNo = :P17_UPDATE_EMPNO;
  
    -- Then compare it with the original data.
    if :P17_ORIGINAL_JOB = v_newjob and
       :P17_ORIGINAL_SAL  = v_newsal and
       :P17_ORIGINAL_DEPT = v_newdept
    then
         -- The record hasn't changed, so update it.
         update EMP
         set Job    = :P17_UPDATE_JOB,
             Sal    = :P17_UPDATE_SAL,
             DeptNo = :P17_UPDATE_DEPT
         where EmpNo = :P17_UPDATE_EMPNO;

    else
         -- The record has changed, so abort.
         raise_application_error(-20000,  
                      'The record is out of date. Get it again.');
    end if;
end;

