create or replace trigger triger_test
before
update on dept
for each row
begin
dbms_output.put_line('변경 전 컬럼 값:'|| :old.dname);
dbms_output.put_line('변경 후 컬럼 값:'|| :new.dname);
end;
/
update dept set dname='총무부' where deptno='30';
create or replace trigger check_delete
before delete on emp
begin
if to_char(sysdate,'DY') in ('목','금') then
raise_application_error(-20007,'목,금요일은 안됨');
end if;
end;
/
delete from emp;
select to_char(sysdate,'DY') from dual
create or replace trigger sum_trigger
before
insert or update on emp
for each row
declare
avg_sal number;
begin
select round(avg(sal),3)
into avg_sal
from emp;
dbms_output.put_line('급여평균:'|| avg_sal);
end;
/
insert into emp(empno,ename,sal,hiredate,deptno) values(1001,'KIM',3000,sysdate,30);
create or replace trigger emp_sal_chk
before insert or update of sal on emp
for each row
begin
if :new.job='CLERK' and :new.sal > 2000 then
raise_application_error(-20002,'너무 높음');
end if;
end;
/
update emp set sal=sal+2000 where empno=7369;
update emp set sal=sal+2000 where empno=7876;
'개발 > sql' 카테고리의 다른 글
oracle 우편번호 저장하기 (0) | 2015.10.13 |
---|---|
oracle sql loader,고정길이 컨트롤 파일,position (0) | 2015.10.12 |
oracle sql procedure (0) | 2015.10.08 |
oracle sql function,procedure (0) | 2015.10.08 |
oracle 중간점검 (0) | 2015.10.07 |
댓글