728x90
반응형
SMALL
<SYS SESSION>
CREATE USER green IDENTIFIED BY oracle;
GRANT CREATE SESSION TO green;
CREATE TABLE audit_emp_sal (
name VARCHAR2(30),
day TIMESTAMP,
id NUMBER,
old_sal NUMBER,
new_sal NUMBER
);
CREATE OR REPLACE PROCEDURE update_proc (
p_id IN NUMBER )
IS
BEGIN
UPDATE hr.employees
SET salary = salary * 1.1
WHERE employee_id = p_id;
END update_proc;
/
SELECT salary
FROM hr.employees
WHERE employee_id = 100;
execute update_proc(100);
GRANT EXECUTE ON hr.update_proc TO green;
SELECT * FROM user_tab_privs;
CREATE OR REPLACE TRIGGER sal_audit
AFTER
UPDATE OF salary ON hr.employees
FOR EACH ROW
WHEN (new.salary != old.salary)
BEGIN
IF :new.salary != :old.salary THEN
INSERT INTO audit_emp_sal (NAME, DAY, ID, old_sal, new_sal)
VALUES (USER, systimestamp, :NEW.employee_id, :OLD.salary, :NEW.salary);
END IF;
END sal_audit;
/
<green session>
SELECT * FROM user_tab_privs;
execute hr.update_proc(100);
commit;
<hr session>
SELECT * FROM hr.audit_emp_sal;
<green session>
execute hr.update_proc(101);
<hr session>
SELECT * FROM hr.audit_emp_sal;
UPDATE hr.employees
SET salary = salary*1.1
WHERE employee_id =101; <- wditing, no wait(green session 에서 rollback 하는 순간)
-- 생성된 트리거 조회
SELECT * FROM user_triggers;
DROP TRIGGER sal_audit;
SELECT * FROM user_source WHERE name = 'UPDATE_PROC';
728x90
반응형
LIST
'Data Base > PL SQL' 카테고리의 다른 글
231108 PL/SQL 독립 트랜잭션(Autonomous Transaction), 문맥전환(SQL엔진, PL/SQL 엔) (0) | 2023.11.08 |
---|---|
231108 PL/SQL 복습_ PROCEDURE, TRIGGER (0) | 2023.11.08 |
231107 PL/SQL TRIGGER VIEW, 복합뷰 (0) | 2023.11.07 |
231107 PL/SQL DML TRIGGER, DML ROW TRIGGER (0) | 2023.11.07 |
231106 PL/SQL TRIGGER, FOR EACH ROW(행트리거),조건부술어 (1) | 2023.11.06 |