Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-28
1
Medium Priority
?
6,676 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
KJlt earned 375 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to recover a database from a user managed backup

610 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