Хотя ваш комментарий говорит, что работает как шарм , рассмотрите возможность его упрощения - не нужно использовать локальную переменную или отличать импорт от обновления.
SQL> create or replace trigger trg_block_prov
2 before update or insert on emp
3 for each row
4 begin
5 if :new.comm > :new.sal * 0.5 then
6 raise_application_error(-20001, 'prov greater than 50% of sal');
7 end if;
8 end;
9 /
Trigger created.
Пример обновления:
SQL> select ename, sal, comm From emp where ename = 'SMITH';
ENAME SAL COMM
---------- ---------- ----------
SMITH 800
SQL> update emp set comm = 500 where ename = 'SMITH';
update emp set comm = 500 where ename = 'SMITH'
*
ERROR at line 1:
ORA-20001: prov greater than 50% of sal
ORA-06512: at "SCOTT.TRG_BLOCK_PROV", line 3
ORA-04088: error during execution of trigger 'SCOTT.TRG_BLOCK_PROV'
SQL> update emp set comm = 300 where ename = 'SMITH';
1 row updated.
SQL> select ename, sal, comm From emp where ename = 'SMITH';
ENAME SAL COMM
---------- ---------- ----------
SMITH 800 300
Пример вставки:
SQL> insert into emp (empno, ename, sal, comm) values (1, 'lf', 1000, null);
1 row created.
SQL> insert into emp (empno, ename, sal, comm) values (2, 'bf', 1000, 700);
insert into emp (empno, ename, sal, comm) values (2, 'bf', 1000, 700)
*
ERROR at line 1:
ORA-20001: prov greater than 50% of sal
ORA-06512: at "SCOTT.TRG_BLOCK_PROV", line 3
ORA-04088: error during execution of trigger 'SCOTT.TRG_BLOCK_PROV'
SQL> insert into emp (empno, ename, sal, comm) values (2, 'bf', 1000, 400);
1 row created.
SQL> select ename, sal, comm From emp where empno in (1, 2);
ENAME SAL COMM
---------- ---------- ----------
lf 1000
bf 1000 400
SQL>