Call raise_application_error to report an error in a trigger : Trigger « Trigger « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> CREATE TABLE employee (
  2  id          number,
  3  name        varchar(100),
  4  birth_date  date,
  5  gender      varchar2(30) );

Table created.

SQL>
SQL> CREATE TRIGGER   employee_bir
  2  BEFORE INSERT ON employee
  3  FOR EACH ROW
  4  begin
  5    if upper(:new.name) = 'J' then
  6      raise_application_error(20000, 'Sorry, that genius is not allowed.');
  7    end if;
  8  end;
  9  /

Trigger created.

SQL>
SQL> INSERT INTO employee (id,name,birth_date,gender )VALUES (100,'J',to_date('19230823', 'YYYYMMDD'),'MALE' );
INSERT INTO employee (id,name,birth_date,gender )VALUES (100,'J',to_date('19230823', 'YYYYMMDD'),'MALE' )
            *
ERROR at line 1:
ORA-21000: error number argument to raise_application_error of 20000
is out of range
ORA-06512: at "JAVA2S.EMPLOYEE_BIR", line 3
ORA-04088: error during execution of trigger 'JAVA2S.EMPLOYEE_BIR'


SQL>
SQL> drop table employee;

Table dropped.








28.2.Trigger
28.2.1.Triggers
28.2.2.System triggers
28.2.3.Creating a Trigger
28.2.4.Trigger Blocks
28.2.5.Trigger that output old value
28.2.6.DML Trigger Example
28.2.7.Firing a Trigger
28.2.8.The use of a trigger
28.2.9.INSERTING, DELETING and UPDATING Predicates
28.2.10.Reference current user name in trigger
28.2.11.Call raise_application_error to report an error in a trigger
28.2.12.Use cursor in trigger
28.2.13.Check the status of the trigger
28.2.14.Show errors for a trigger