Exception treatment with Commit and Rollback

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
josehw
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 5
Joined: Mon, 04 May 2009 8:51 am
Location: Maringá - PR

Hello, I would like to know how to make a correct treatment of my triggers and procedures, using Commit and Rollback. it cost
User avatar
dr_gori
Moderador
Moderador
Posts: 5027
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Like this?
Do you want to do RollBack if you give any errors during the execution of your procedure?
josehw
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 5
Joined: Mon, 04 May 2009 8:51 am
Location: Maringá - PR

Yes, for example, I have a trigger q has 2 inserts, what do I need is q when an error occurs in the 2nd insert, give a rollback in the information q have been inserted in the 1st insert, titted?
marcelo_nunes
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 17
Joined: Mon, 08 Sep 2008 7:35 pm
Location: Ribeirão Preto - SP
Marcelo Nunes
Analista/Desenvolvedor Oracle

If you are using Pragma AutoNomous_Transaction in the trigger, you will have to treat insert to insert for if this process falls on the exception it does a rollback, with this you put the commit only at the end of the trigger.
But if you are not using Pragma AutoNomous_Transaction, the trigger itself will not let the information be "commitates" and will give a rollback in everything that was performed there because you can not put commit in trigger.
josehw
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Posts: 5
Joined: Mon, 04 May 2009 8:51 am
Location: Maringá - PR

Thanks for the attention and the answer!
User avatar
fsitja
Rank: OraSauro
Rank: OraSauro
Posts: 611
Joined: Mon, 19 Jan 2009 4:29 pm
Location: Gaúcho no Rio de Janeiro - RJ
"The scars exist to remind us that the past was real"
Campanha: Como fazer uma pergunta e obter uma resposta.
http://tkyte.blogspot.com/2005/06/how-t ... tions.html

OCA & OCP Developer — OCE SQL Expert — OCS Data Warehousing Specialist

You do not need Autonomous Transaction in your case, since there is dependence between the two operations. Let the trigger give a raise on the exception on the 2nd insert normally. At the exit of your DML that fired the trigger, take the exception and give the rollback. Will cancel everything.

Now, very careful with Autonomous Transaction. The ideal is to treat everything in a transaction only and decide by the Commit or RollBack at the end, not to end up detonating with the consistency of the database.
RodrigoValentim
Moderador
Moderador
Posts: 367
Joined: Tue, 25 Mar 2008 3:41 pm
Location: Salvador - BA
Rodrigo Valentim
Analista de Sistemas
Oracle Developer

Campanha: Faça uma pesquisa antes de perguntar!!!

In trigger it is not these situations and yes in the application, why do not you test the situation before the process go to the bank?


Once the trigger action is made, there is no more rollback because of the Commit.
Post Reply
  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 1 guest