PL/SQL Trigger 6 – Before Insert Trigger Example

Create a Table EMP_<employee_id> with following fields
        EMPNO NUMBER
        NAME    VARCHAR2
        BSAL NUMBER
        ALLW NUMBER
        TSAL   NUMBER


Create an Audit Table AUDIT_EMP_<employee_id> with following fields
       DB_USER    VARCHAR2
       UPDATED_ON   DATE

 

Create a BEFORE trigger which is triggered before inserting values into EMP table and which updates the TSAL as sum of bsal and allw

Answer

CREATE OR REPLACE TRIGGER bf_empp
BEFORE INSERT ON EMPPP_a5518 FOR EACH ROW
declare
    tot number(5);
BEGIN
    
    :NEW.TSAL:=:NEW.BSAL + :NEW.ALLW;
    
END bf_empp;
/

 

INSERT INTO EMPPP_a5518 (EMPNO, NAME, BSAL, ALLW) VALUES (1,'jijo',45,67);


 

You can leave a response, or trackback from your own site.

Leave a Reply