oracle-databasesqlplus

In Oracle, does a DDL script need commit statements when run with sqlplus?


DDL scripts do not need COMMIT statements as per the docs.

If I run these statements in SQL Developer, no commit is required:

CREATE TABLE dummy_table(ID NUMBER(38,0) NOT NULL PRIMARY KEY);
CREATE SEQUENCE dummy_seq START WITH 1 INCREMENT BY 1 NOCACHE;

When I run with sqlplus, log says :

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jul 3 11:28:54 2024
Version 19.3.0.0.0
 
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
 
Last Successful login time: Wed Jul 03 2024 11:28:53 +02:00
 
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.23.0.0.0
 
 
Table created.
 
 
Sequence created.
 
SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.23.0.0.0

But when I check if the table and sequence were created, I can see that they were not created.

After adding COMMIT at the end of the script, still neither of them were created.

Only after adding COMMIT after each statement, both the table and the sequence were created.

My sqlplus command:

sqlplus  USER/"PASSWORD"@DATABASE @ /path/to/script.sql

Solution

  • No.

    DDL causes everything in your session to be implicitly committed.

    From the Docs:

    Oracle Database issues an implicit COMMIT under the following circumstances:

    Before any syntactically valid data definition language (DDL) statement, even if the statement results in an error

    After any data definition language (DDL) statement that completes without an error

    This is true for any client side application issuing the work, INCLUDING but not limited to, SQLPlus.

    If you don't see your table and sequence when you 'went back in' to 'check it' - you either connected to the wrong database or you were looking in the wrong schema.