Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple query about a database trigger in Oracle

Posted on 2008-10-06
3
Medium Priority
?
598 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 200 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

971 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