Transactions in Oracle

 Transactions in Oracle


A transaction is a sequence of SQL statements that are treated as a single unit of work. Transactions are used to ensure data consistency and maintain the integrity of the database. A transaction can be committed or rolled back, depending on whether it is successful or not. Here is an example:


BEGIN

   -- start transaction

   UPDATE accounts SET balance = balance - 100 WHERE account_id = 123;

   UPDATE accounts SET balance = balance + 100 WHERE account_id = 456;

   -- end transaction

   COMMIT;

END;

This starts a transaction that updates the balance of two accounts. If the transaction is successful, it is committed. If there is an error, the transaction is rolled back.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...