Skip to main content

Posts

Showing posts with the label SQL Trigger

Create or replace trigger before insert on field in sql

1.Create  or replace trigger before insert on field in sql Create or replace trigger t1 Before insert on Employee For each row declare v_firstname Employee.firstname%type; v_lastname Employee.lastname%type; Begin DBMS_OUTPUT.PUT_LINE('You inserted the first Name:'|| :NEW.FIRSTNAME); DBMS_OUTPUT.PUT_LINE('You inserted the first Name:'|| :NEW.LASTNAME); Begin select distinct firstname into v_firstname from Employee where firstname=:NEW.FIRSTNAME; IF(:NEW.FIRSTNAME = v_firstname) THEN DBMS_OUTPUT.PUT_LINE('This first name exists already in the table Employee.'); end if; exception when no_data_found then DBMS_OUTPUT.PUT_LINE('This first name does not exist in the table Employee.'); End; Begin select distinct lastname into v_lastname from Employee where lastname=:NEW.lastNAME; IF(:NEW.LASTNAME = v_lastname) THEN DBMS_OUTPUT.PUT_LINE('This last name exists already in the table Employee....

Example of trigger using procedure language

Example of trigger using procedure language CREATE OR REPLACE TRIGGER Trig_test AFTER INSERT ON EMP1 FOR EACH ROW DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN test_T; -- Test_T is a Procedure commit; END Trig_test create or replace procedure test_T AS declare v_empno emp.EMPNO%type; cursor c1 is select empno from emp1 where empno is null; BEGIN open c1;loop fetch c1 into v_empno; exit when c1%notfound; update emp1 set empno = empno_seq.nextval where empno is null; end loop; close c1; Exception when others then null; end;