473,473 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to prevent table entry from being deleted but perform statements in the body of a trigger ?

Hi everybody!

My problem is as following:

I have a trigger which fires on delete of a table row. The body of the
trigger checks and manipulates entries in other tables.

If the entries have certain values, I would like the row of the table
which has fired the trigger not to be deleted. As far as I understood
this problem could be solved by a user defined exemption. But when
using an exemption all the manipulations in the other tables are
rolled back as well which I don't want them to do. Furthermore the
trigger should then write a row into the table "ERRORS" which contains
information about the kind of the error and the time it occured.

Does anybody have an idea how to solve this problem?

Thanks Robert
Jul 19 '05 #1
1 5568
andrewst <me*********@dbforums.com> wrote in message news:<30****************@dbforums.com>...
Originally posted by Robertgl
Hi everybody!

My problem is as following:

I have a trigger which fires on delete of a table row. The body of the
trigger checks and manipulates entries in other tables.

If the entries have certain values, I would like the row of the table
which has fired the trigger not to be deleted. As far as I understood
this problem could be solved by a user defined exemption. But when
using an exemption all the manipulations in the other tables are
rolled back as well which I don't want them to do. Furthermore the
trigger should then write a row into the table "ERRORS" which contains
information about the kind of the error and the time it occured.

Does anybody have an idea how to solve this problem?

Thanks Robert

The word is "exception" not "exemption".

It is not necessarily the case that all changes will be rolled back:
your application can decide how to handle the exception, e.g.

DECLARE
my_exception EXCEPTION;
PRAGMA EXCEPTION_INIT( my_exception, -20010 );
BEGIN
INSERT INTO t1(a) VALUES (1);
BEGIN
DELETE FROM t2 WHERE b=2;
EXCEPTION
WHEN my_exception THEN
-- Your handler code here
NULL;
END;
COMMIT;
END;

In this example, if the BEFORE DELETE trigger on t2 had raised error
ORA-20010 (by calling RAISE_APPLICATION_ERROR(-20010,'some message'))
then the exception is effectively ignored (NULL statement). There is no
rollback, and the insert into t1 is still committed at the end.

If the trigger needs to insert a row into the ERRORS table, such that
that row still exists even if the main transaction rolls back, then you
should perform the insert into ERRORS in a procedure with PRAGMA
AUTONOMOUS_TRANSACTION:

PROCEDURE log_error( ... )
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO errors( ... ) VALUES ( ... );
COMMIT;
END;


Hi Andrew!

Yes, the PRAGMA AUTONOMOUS_TRANSACTION did it!! Thanks a lot for
helping out so quickly.

Robert
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: toedipper | last post by:
Hello, I am designing a table of vehicle types, nothing special, just a list of unique vehicle types such as truck, lorry, bike, motor bike, plane, tractor etc etc For the table design I am...
1
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i...
7
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
1
by: Leanne | last post by:
I am doing customization for microsoft POS. I manually added a record to a table. The manage and maintenance of this table are done by POS, and user can update the contents of this table. Is there...
2
by: Mark | last post by:
I have a form with two sub forms. The form is set to data entry. The form is bound directly to a table I have two buttons at the bottom of the screen. One button is named reject and one is named...
3
by: Mitramirsa | last post by:
I want to write a trigger so that rows deleted from the table are logically-deleted, rather than being actually removed. That is, such rows are marked as being deleted, rather than actually being...
1
by: RobertGl | last post by:
Hi everybody! My problem is as following: I have a trigger which fires on delete of a table row. The body of the trigger checks and manipulates entries in other tables. If the entries have...
5
by: =?ISO-8859-1?Q?Gear=F3id?= | last post by:
Hey, This may sound odd, but is there anyway to catch the current or just run query from inside a trigger? Kinda like how profiler displays the query just as you've run it, along with all the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.