Question

First, off, let me start by saying the code below isn't necessarily a good option for the output in question, but this is not a real life situation, it's just a school exercise.

I'm supposed to create a trigger that outputs emp_id and salary when the latter is more than 100,000. The trigger is created with no errors but nothing is printed (i.e. DBMS_OUTPUT), which makes me think the condition for the trigger is not set correctly, but I can't see where the problem is.

I'm using SQLPLUS.

This is the table:

Name                                      Null?    Type
----------------------------------------- -------- -------------

EMP_ID                                    NOT NULL NUMBER(10)
FNAME                                              NVARCHAR2(20)
LNAME                                              NVARCHAR2(20)
MANAGER_EMP_ID                                     NUMBER(10)
SALARY                                             NUMBER(38)

This is my trigger:

CREATE OR REPLACE TRIGGER check_salary
AFTER INSERT OR UPDATE OF SALARY ON EMPLOYEE
FOR EACH ROW
WHEN (NEW.SALARY > 100000)
BEGIN
    DBMS_OUTPUT.PUT('Salary value for ' || :OLD.EMP_ID || ' IS ' || :NEW.SALARY);
END;
/

And this is the insert I am using which doesn't set the trigger off:

INSERT INTO EMPLOYEE(FNAME,LNAME,SALARY) VALUES ('Mary','Jane',100001);

(OBS: EMP_ID is being inserted automatically by another trigger from a previous exercise).

The row is successfully added, however the is no DBMS_OUTPUT.

Thank you.

Was it helpful?

Solution

I detected what was wrong in my code after all. It seems that DBMS_OUTPUT.PUT() is not enough to print, I need DBMS_OUTPUT.PUT_LINE().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top