-- Listing 7-12. Second Revision of the Update Code of Listing 7-4
declare
    v_valuesToHash apex_t_varchar2;
begin
    -- First re-read the data.
    select apex_t_varchar2(Job, Sal, DeptNo)
    into v_valuesToHash
    from EMP
    where EmpNo = :P17_UPDATE_EMPNO;

    -- Then compare it with the original data.
    if :P17_HASH = apex_util.get_hash(v_valuesToHash)
    then
        -- The record hasn't changed, so update it.
        update EMP
        set Job    = :P17_UPDATE_JOB,
            Sal    = :P17_UPDATE_SALARY,
            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;

