From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: EXCEPTION_WHEN_OTHERS
Date: Wed, 10 Jan 2007 11:41:04 +0100
Date: 2007-01-10T11:41:04+01:00 [thread overview]
Message-ID: <50ju5kF1gbih2U1@mid.individual.net> (raw)
In-Reply-To: 1168349612.603238.225860@m30g2000cwm.googlegroups.com
Chris wrote:
> Hi,
>
> Could someone please help me with regards to a problem I am having with
> some PL/SQL code.
Jason already replied, but to further clarify: what you have here is a
misleading indentation. It should be
if :contract.old_contract IS NOT NULL AND
:contract.new_contract IS NOT NULL
THEN
BEGIN
UPDATE contracts
SET contract_no = :contract.new_contract
WHERE contract_no = :contract.old_contract;
message ('update successful');
EXCEPTION WHEN OTHERS THEN
message ('update has failed');
END;
END IF;
Note that EXCEPTION is at the same level than BEGIN. As you can clearly see
now, any exception raised between BEGIN and EXCEPTION will cause the
exception block to be executed, whereas if no exception occurs, all the
code before EXCEPTION will be executed.
>
> The code is:
>
> if :contract.old_contract IS NOT NULL AND
> :contract.new_contract IS NOT NULL THEN
> BEGIN
> UPDATE contracts
> SET contract_no = :contract.new_contract
> WHERE contract_no = :contract.old_contract;
> EXCEPTION WHEN OTHERS THEN
> message ('update has failed');
> END;
> END IF;
>
> As you can see I have a message saying 'update failed' when there is an
> exception i.e. when the save fails. This works fine as does the rest
> of the code.
>
> What I need however is a way of getting a message 'save was successful'
> when there are no exceptions.
>
> Any help would be great.
>
> Thanks
> Chris
prev parent reply other threads:[~2007-01-10 10:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-09 13:33 EXCEPTION_WHEN_OTHERS Chris
2007-01-09 14:45 ` EXCEPTION_WHEN_OTHERS Jason King
2007-01-10 10:41 ` Alex R. Mosteo [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox