SQL> SQL> create or replace trigger yutao708 2 before update of sal on scott.emp 3 for each row 4 begin 5 if (:old.job = 'SALESMAN') then 6 :new.comm := :new.sal * 0.8; 7 end if; 8 end; 9 /Trigger createdSQL> update emp set sal = 1000 where empno=7499;1 row updatedSQL> commit;Commit completeSQL> select * from emp where empno=7499;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----- ---------- --------- ----- ----------- --------- --------- ------ 7499 ALLEN SALESMAN 7698 1981-2-20 1000.00 800.00 30SQL>
--触发器: SQL> CREATE OR REPLACE TRIGGER emp_trigger_on_sal 2 BEFORE UPDATE OF sal ON emp 3 FOR EACH ROW 4 BEGIN 5 :NEW.comm:=(:NEW.sal/:OLD.sal)*:OLD.comm; 6 END; 7 /Trigger created. SQL> SELECT * FROM emp WHERE empno=7521; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----- 7521 WARD SALESMAN 7698 22-2月 -81 2500 250 30SQL> UPDATE emp SET sal =1250 WHERE empno= 7521;1 row updated.SQL> SELECT * FROM emp WHERE empno=7521; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----- 7521 WARD SALESMAN 7698 22-2月 -81 1250 125 30SQL>
create or replace trigger update_sal before update of sal on Tab_emp for each row AS begin if :old.job=salename and :new.sal<>:old.sal then :new.comm=:old.comm*(:new.sal/:old.sal) END
SQL> create or replace trigger emp_trigger_on_sal 2 before update of sal on emp 3 for each row 4 begin 5 :new.comm:=(:new.sal/:old.sal)*:old.comm; 6 end; 7 /
create or replace trigger tri_Sal_EMP before update of sal on emp Referenceing new as new old as old for each row when job='SALEMAN' AS begin :new.comm=:old.comm*(:new.sal/:old.sal) END
create or replace trigger tri_empcom before update on emp for each row when(new.job='SALEMAN') begin :new.comm:=((:new.sal-:old.sal)/:old.sal)*:old.comm; end;
SQL>
SQL> create or replace trigger yutao708
2 before update of sal on scott.emp
3 for each row
4 begin
5 if (:old.job = 'SALESMAN') then
6 :new.comm := :new.sal * 0.8;
7 end if;
8 end;
9 /Trigger createdSQL> update emp set sal = 1000 where empno=7499;1 row updatedSQL> commit;Commit completeSQL> select * from emp where empno=7499;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7499 ALLEN SALESMAN 7698 1981-2-20 1000.00 800.00 30SQL>
--触发器:
SQL> CREATE OR REPLACE TRIGGER emp_trigger_on_sal
2 BEFORE UPDATE OF sal ON emp
3 FOR EACH ROW
4 BEGIN
5 :NEW.comm:=(:NEW.sal/:OLD.sal)*:OLD.comm;
6 END;
7 /Trigger created.
SQL> SELECT * FROM emp WHERE empno=7521; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- -----
7521 WARD SALESMAN 7698 22-2月 -81 2500 250 30SQL> UPDATE emp SET sal =1250 WHERE empno= 7521;1 row updated.SQL> SELECT * FROM emp WHERE empno=7521; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- -----
7521 WARD SALESMAN 7698 22-2月 -81 1250 125 30SQL>
before update of sal on Tab_emp
for each row
AS
begin
if :old.job=salename and :new.sal<>:old.sal then
:new.comm=:old.comm*(:new.sal/:old.sal)
END
SQL> create or replace trigger emp_trigger_on_sal
2 before update of sal on emp
3 for each row
4 begin
5 :new.comm:=(:new.sal/:old.sal)*:old.comm;
6 end;
7 /
before update of sal on emp
Referenceing new as new old as old
for each row
when job='SALEMAN'
AS
begin
:new.comm=:old.comm*(:new.sal/:old.sal)
END
create or replace trigger tri_empcom before update on emp for each row
when(new.job='SALEMAN')
begin
:new.comm:=((:new.sal-:old.sal)/:old.sal)*:old.comm;
end;