HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaModerate

What is the difference between terminating an Oracle sql statement with semicolon or with a slash on the next line?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thewhatstatementsqlwithlinesemicolonslashnextdifference

Problem

The following two queries seem to be equivalent when executed in sql*plus:

1.

select * from user_tables;


2.

select * from user_tables
/


Is there any difference between both versions?

Solution

There is no difference for a single SQL statement. The '/' character on its own line tells SQL*Plus to execute the command in the buffer. You can use the semicolon at the end of most SQL statements as a shorthand for the '/'. If you want to execute a PL/SQL block or to execute a handful of SQL statements like CREATE TYPE, however, you need to use the '/'

SQL> begin
  2    null;
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> create type foo as object (
  2    col1 number,
  3    col2 number );
  4  /

Type created.


Different tools may have slightly different conventions for how you execute multiple SQL and PL/SQL statements in a script so be aware that this is SQL*Plus specific.

Code Snippets

SQL> begin
  2    null;
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> create type foo as object (
  2    col1 number,
  3    col2 number );
  4  /

Type created.

Context

StackExchange Database Administrators Q#1305, answer score: 11

Revisions (0)

No revisions yet.