How do transactions work in Oracle? How does Oracle support transactions?

In Oracle, there are just two transaction modes: implicit and autocommit. Just like with SQL Server transactions (INSERT LINK HERE!!), if JDBC or ODBC drivers are used to connect to the Oracle database, then you should read the documentation to see what kind of transaction support is provided.

Here are more details on the two transaction modes in Oracle.

What is autocommit mode in Oracle?

In autocommit mode, each SQL statement is treated as a separate transaction. This is accomplished by automatically committing each SQL statement as it finishes – and is why it’s called autocommit mode. But, Oracle is different from other DBMS’s (like SQL Server) because autocommit is not the default mode.




How to set autocommit mode in Oracle?

Here are the commands to set autocommit mode in Oracle to ON and OFF:

SET AUTOCOMMIT OFF
SET AUTOCOMMIT ON

What is implicit mode in Oracle?

Implicit mode, and not autocommit mode, is actually the default transaction mode in Oracle. This means that when a database user first connects to the database and starts a new session, a transaction is also implicitly started. If one transaction ends either with a rollback or a commit statement, then a new transaction will be started automatically.

When will a transaction end with a commit in Oracle?

There are three different scenarios when a transaction will end with a commit. Here are those 3 scenarios:

  • 1. If the database user explicitly issues the SQL COMMIT statement.
  • 2. If the user sends an EXIT command, which means that the database session has ended normally.
  • 3. If the user submits a SQL DDL (Data Definition Language) command, like ALTER, DROP or CREATE.
  • When will a transaction end with a rollback in Oracle?

    There are two possible situations in which a transaction will end with a rollback:

  • 1. If the database user submits a SQL ROLLBACK statement explicitly.
  • 2. If the database user session ends under abnormal circumstances. This could happen if the database crashes, or even if the connection used by the client is cancelled.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.

  • gyana nayak

    Discuss this chapte with some more example with full explanation please.