trigger 사용

2024. 11. 13. 08:53Oracle/Oracle Study

반응형

1. 테이블 확인

SQL> select * from scott.tmp_result;

 

2. history 테이블 생성

SQL> create table scott.table_history as select ename, sysdate dt from scott.tmp_result where 1=2;
Table created.

 

3. trigger 생성

create or replace trigger table_history_trigger
before insert on scott.tmp_result
for each row
begin
    if inserting then
        insert into scott.table_history values(:new.ename, sysdate);
    end if;
end table_history_trigger
;
/

 

4. insert 및 확인

SQL> insert into scott.tmp_result values(9999,'CPU','Main',40,'Computer');
1 row created.

 

SQL> select * from scott.table_history;

반응형