RSS

Commit/Rollback in Oracle

12 Apr

How to do a transaction using commit and rollback in Oracle:

begin
  -- statement 1
  delete from [TableName];
  -- the savepoint used for later rollback
  savepoint [SavePointName];

  begin
    -- statement 2
    insert into [TableName]
      ([Column1],... )
    values
      ([Value1],... );
    -- statement 3
    insert into [TableName]
      ([Column1],... )
    values
      ([Value1],... );

  exception
    when others then
      -- rollback if either statement 2 or 3 fails
      rollback to [SavePointName];
  end;

  commit;

end;

Reference: Howto use Rollback/Commit in Oracle SQL

Advertisements
 
Leave a comment

Posted by on April 12, 2012 in Oracle, SQL

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: