Solved

Simple query about a database trigger in Oracle

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now