This is a pretty straightforward trigger which is executing but is not printing the simple message:
CREATE OR REPLACE TRIGGER t_emp
AFTER INSERT OR DELETE OR UPDATE ON employee
FOR EACH ROW
ENABLE
DECLARE
v_user VARCHAR2(20);
BEGIN
SELECT user INTO v_user FROM DUAL;
IF INSERTING THEN
DBMS_OUTPUT.PUT_LINE('One row inserted by ' || v_user);
ELSIF DELETING THEN
DBMS_OUTPUT.PUT_LINE('One row deleted by ' || v_user);
ELSIF UPDATING THEN
DBMS_OUTPUT.PUT_LINE('One row updated by ' || v_user);
END IF;
END;
/
Table:
CREATE TABLE employee
(
s_name varchar2(30)
);
Simple test case:
INSERT INTO employee
VALUES('Kafka');
However, yields no message although it gets executed. Now here is where it gets interesting. If I run a testing anonymous block like
BEGIN
DBMS_OUTPUT.PUT_LINE('One row inserted by ' );
end;
/
I get the first printout of the trigger(which was supposed to be printed when I executed the DML statement) followed by the current message ("One row inserted by"). I have tested other pl/sql blocks and they execute fine. This seems to be a problem only with triggers (I also tried a couple of others). What could be the issue?
Thanks
select from dual- PL/SQL has a handy assignment operator, so you could just declarek_user constant user_users.username%type := user;