Solved

Can Before Trigger cancel the insert, update, delete opations?

Posted on 2006-06-28
1
6,667 Views
Last Modified: 2009-05-20
hello

Can Before Trigger cancel the insert, update, delete opations.
Please help me!

CREATE OR REPLACE TRIGGER fnsonld.emp_flds
   BEFORE UPDATE
   ON fnsonld.emp_flds
   FOR EACH ROW
DECLARE
   PRAGMA AUTONOMOUS_TRANSACTION;
   fld_data_type varchar2(50);
BEGIN
      
   IF :OLD.FLDTYPE <> :NEW.FLDTYPE then
  --Cancel update
  end if;

EXCEPTION
   WHEN OTHERS
   THEN
      -- Consider logging the error and then re-raise
      RAISE;
END;
/
0
Comment
Question by:jambuul
1 Comment
 
LVL 2

Accepted Solution

by:
KJlt earned 125 total points
ID: 16999420
Solution 1:

IF :OLD.FLDTYPE <> :NEW.FLDTYPE then
  -- if you need to get error message
  raise_application_error(-20001,'Insert canseled');
end if;

Solution 2:

IF :OLD.FLDTYPE <> :NEW.FLDTYPE then
  -- if you need "silent cancel"
  -- work only on before update triggers, as in your case
  :NEW.FIELD1:=:OLD.FIELD1;
  :NEW.FIELD2:=:OLD.FIELD2;
  -- ... all the table fields
  :NEW.FIELDn:=:OLD.FIELDn;
end if;
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.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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…

825 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