From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d721ab90148a4f76 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: EXCEPTION_WHEN_OTHERS Date: Wed, 10 Jan 2007 11:41:04 +0100 Message-ID: <50ju5kF1gbih2U1@mid.individual.net> References: <1168349612.603238.225860@m30g2000cwm.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net hwj0RsLEN2Y72aE99PvrsAtqSsDS2f0XhjjS8+JAIDI1DwkX4= User-Agent: KNode/0.10.4 Xref: g2news2.google.com comp.lang.ada:8103 Date: 2007-01-10T11:41:04+01:00 List-Id: 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