How to use Rollback / Commit in Oracle SQL

I am trying to use transactional functionality in Oracle SQL for the first time and cannot find a suitable explanation. I understand that the start of a new session will begin with a new transaction. I also understand that commit / rollback is used to complete it. What I'm trying to do is execute two statements, and if I fail one of them, discard any changes that they could make and continue. How can I check this condition and perform a commit or rollback accordingly?

+6
sql oracle transactions
source share
2 answers

Use a PL / SQL block and write something like this:

begin statement_zero; savepoint my_savepoint; begin -- if either of these fail, then exception section will be executed statement_one; statement_two; exception when others then rollback to my_savepoint; end; statement_three; commit; end; 

See also http://www.adp-gmbh.ch/ora/concepts/transaction.html

+15
source share

Along with a nice exaplample ObiWanKenobi containing a detailed explanation of Oracle transactions can be found in Chapter 4 of the Oracle Concepts Guide (I’ve provided 10.2 link, you can also find a document suitable for your version on the Oracle website). I suggest you read this chapter to understand how Oracle handles transaction management, and the document as a whole is a very good piece of information in order to understand how Oracle DB works.

+2
source share

All Articles