140907 |
---|
Подобные триггеры нормально работают при сравнении числовых данных. А с текстом что-то не получается, и я не понимаю почему. |
Потому-что проверка данных на вшивость происходит до INSET/UPDATE независимо от типа данных. И с числами тоже:
SQL> create table tbl(n number(1));
Table created.
SQL> create or replace
2 trigger tbl_bir
3 before insert
4 on tbl
5 for each row
6 begin
7 if :new.n >= 10 then raise_application_error(-20500,'N must by less than 10'); end if;
8 end;
9 /
Trigger created.
SQL> insert into tbl values(99);
insert into tbl values(99)
*
ERROR at line 1:
ORA-01438: value larger than specified precision allowed for this column
SQL>
А ты скорее всего использовал "безразмерный" NUMBER:
SQL> create table tbl(n number);
Table created.
SQL> create or replace
2 trigger tbl_bir
3 before insert
4 on tbl
5 for each row
6 begin
7 if :new.n >= 10 then raise_application_error(-20500,'N must by less than 10'); end if;
8 end;
9 /
Trigger created.
SQL> insert into tbl values(99);
insert into tbl values(99)
*
ERROR at line 1:
ORA-20500: N must by less than 10
ORA-06512: at "SCOTT.TBL_BIR", line 2
ORA-04088: error during execution of trigger 'SCOTT.TBL_BIR'
SQL>
Кстати, с числами еще сложнее чем со строками, ибо они еще и округляются при превышении размерности дробной части:
SQL> create table tbl(n number(*,1));
Table created.
SQL> create or replace
2 trigger tbl_bir
3 before insert
4 on tbl
5 for each row
6 begin
7 if :new.n >= 10 then raise_application_error(-20500,'N must by less than 10'); end if;
8 end;
9 /
Trigger created.
SQL> insert into tbl values(9.25);
1 row created.
SQL> select * from tbl;
N
----------
9.3
SQL> insert into tbl values(9.95);
insert into tbl values(9.95)
*
ERROR at line 1:
ORA-20500: N must by less than 10
ORA-06512: at "SCOTT.TBL_BIR", line 2
ORA-04088: error during execution of trigger 'SCOTT.TBL_BIR'
SQL>
SY.