Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Triggers & Rollback

Re: Triggers & Rollback

From: Niall Litchfield <n-litchfield_at_audit-commission.gov.uk>
Date: Tue, 9 Apr 2002 16:23:47 +0100
Message-ID: <3cb30783$0$236$ed9e5944@reading.news.pipex.net>


I'm with Daniel here. It seems to me that good design is to do one and only one of the following

  1. Raise the error and warning message.
  2. correct the error programmatically.

if you do both you must run the risk of the user rerunning the transaction with corrected values after you have also corrected them. Or of raising an error message that says 'there was an error but I fixed it so even though this is an error message just ignore it'. This type of error message does not help users.

I'd actually go further and say that the right course of action is point 1, users NOT developers (or DBAs) are responsible for data entry so they should be made to get it right. of course this leads to user hostile apps if validation conditions are complex, but then I'm a DBA so user hostile apps are just fine <VBG>.

--
Niall Litchfield
Oracle DBA
Audit Commission UK
*****************************************
Please include version and platform
and SQL where applicable
It makes life easier and increases the
likelihood of a good answer

******************************************
"Daniel Morgan" <damorgan_at_exesolutions.com> wrote in message
news:3CB303D7.E10FB3F_at_exesolutions.com...

> One way to do this is with an autonomous transaction. You can commit
within the
> trigger and then raise the exception for informational purposes only. I
would,
> however, argue that you probably shouldn't do it and that depending on
what else is
> happening it may not work for you. Another way would be to insert a
message into a
> global temporary table that is always read after each transaction.
Inefficient but
> solves the problem.
>
> Daniel Morgan
>
>
>
> Thomas Kyte wrote:
>
> > In article <497cda72.0204081424.2c5cb81c_at_posting.google.com>,
uwda_at_yahoo.com
> > says...
> > >
> > >I have an BEFORE INSERT trigger that, when a condition is met, I alert
> > >the user with an RAISE_APPLICATION_ERROR. The problem is when I do
> > >that, an automatic rollback happens.
> > >
> > >What I'm trying to accomplish is alert the user that something is
> > >amiss, but then fix it for them. Any ideas?
> > >
> > >
> > > CREATE OR REPLACE TRIGGER trg_foo_bar
> > > before Insert
> > > On table_1
> > > For Each Row
> > >
> > > Begin
> > > if :new.hNumber <> 10 then
> > > raise_application_error(-20101, 'Value not 10!');
> > > :new.hNumber := 10;
> > > end if;
> > > End;
> > >
> > >Thanks
> > >
> > >J.
> >
> > That is just not going to happen.
> >
> > What I could envision is something like this;
> >
> > create or replace package warnings
> > as
> > type myArray is table of varchar2(255) index by binary_integer;
> >
> > messages myArray;
> > end;
> > /
> >
> > create or replace trigger BI_trigger
> > before insert on T
> > declare
> > empty warnings.myArray;
> > begin
> > warnings.messages := empty;
> > end;
> > /
> >
> > CREATE OR REPLACE TRIGGER trg_foo_bar
> > before Insert
> > On table_1
> > For Each Row
> >
> > Begin
> > if :new.hNumber <> 10 then
> > warnings.messages( warnings.messages.count+1 ) := 'wooops, not 10';
> > :new.hNumber := 10;
> > end if;
> > End;
> >
> > and have the client LOOK for messages afterwards. Anything that flings
an error
> > back it by design going to rollback the offending statement (it caused
an ERROR
> > after all!)
> >
> > Seems like the client shouldn't even be putting in a value for this
column -- it
> > should just default and not even be inserted into...
> >
> > --
> > Thomas Kyte (tkyte@us.oracle.com) http://asktom.oracle.com/
> > Expert one on one Oracle, programming techniques and solutions for
Oracle.
> > http://www.amazon.com/exec/obidos/ASIN/1861004826/
> > Opinions are mine and do not necessarily reflect those of Oracle Corp
>
Received on Tue Apr 09 2002 - 10:23:47 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US