/update-salary.sql Secret
Created
July 16, 2024 09:16
給与を更新する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare | |
l_empno emp.empno%type; | |
e_sal_was_changed exception; | |
l_sal_current emp.sal%type; | |
l_sal_old emp.sal%type; | |
l_sal emp.sal%type; | |
begin | |
:P1_ERROR := ''; | |
begin | |
select empno, sal into l_empno, l_sal_current from emp where empno = :P1_EMPNO for update nowait; | |
exception | |
when others then | |
/* ほぼ ORA-00054 resource busy */ | |
:P1_ERROR := '行が更新中です。'; | |
return; | |
end; | |
/* | |
* 変更前の値がl_sal_old、変更後の値がl_sal。 | |
*/ | |
l_sal_old := to_number(:P1_SAL_OLD,'999G999G999G999G999G999G999G999G999G990'); | |
l_sal := to_number(:P1_SAL,'999G999G999G999G999G999G999G999G999G990'); | |
if l_sal_current = l_sal then | |
/* | |
* 現在の給与と変更しようとしてる給与が同じ。 | |
*/ | |
null; | |
elsif l_sal_current <> l_sal_old then | |
/* | |
* 他のセッションにより更新済み。 | |
*/ | |
:P1_ERROR := '他のセッションで更新されています。'; | |
else | |
/* | |
* 給与を更新する。 | |
*/ | |
update emp set sal = l_sal where empno = l_empno; | |
commit; | |
end if; | |
rollback; | |
return; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment