Solved

Simple query about a database trigger in Oracle

Posted on 2008-10-06
3
580 Views
Last Modified: 2013-12-18
Please explain reason for trigger compilation errors
trigquery.txt
0
Comment
Question by:tony_stockman
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 50 total points
ID: 22649579
This line is the problem...

INSERT INTO EMP_HIST VALUES (EMPNO, ENAME, :OLD.COMM, :NEW.COMM, SYSDATE);


you have referenced the empno and ename columns but haven't specified the :old  or :new...  


Note,  when doing an insert, you don't have an old


I suggest modifying the trigger something like this...

CREATE OR REPLACE TRIGGER audit_emp
    AFTER INSERT OR UPDATE OF comm
    ON emptrig
    FOR EACH ROW
BEGIN
    IF INSERTING
    THEN
        INSERT INTO emp_hist
          VALUES   (
                        :new.empno, :new.ename, NULL, :new.comm, SYSDATE
                   );
    ELSE
        INSERT INTO emp_hist
          VALUES   (
                        :old.empno, :old.ename, :old.comm, :new.comm, SYSDATE
                   );
    END IF;
END;

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question