ConorW
ConorW

Reputation: 277

Terminating semicolon in Oracle SQL

I have recently started learning Oracle SQL and am a bit confused about whether or not the terminating semicolon is required (or, indeed, whether or not it is a feature of the particular database program you're using).

At work, I have to use DBVisualizer and there is always a terminating semicolon but in the book 'Oracle SQL by Example', it is quite consistently lacking. Can someone please enlighten me? Thanks.

Upvotes: 2

Views: 1591

Answers (2)

Walter Mitty
Walter Mitty

Reputation: 18950

The question of whether semicolon is a terminator or a separator has been a messy one in computer languages for over forty years. Compare Pascal and Java.

If you accept semicolon as a separator in SQL, then it might not be required in interactive sql, as in Oracle's SQL/plus interpreter. But a SQL parser really has its work cut out for it. SQL obviously wasn't designed to make it easy to write a parser.

consider this:

select 
    College_Name,
    City
from 
    Colleges

How does the parser know the command isn't going to continue with the following?

where
     State = 'CA'

If a sequence of commands, bracketed by some sort of begin-end pair, can also be entered, things get even harder for the parser. The semicolon helps the parser enormously.

In some dialects of interactive SQL, hitting the Enter key twice can trigger execution. In others, a special command like "go" is used for this purpose.

Upvotes: 1

rics
rics

Reputation: 5596

Here is a similar question from dba.stackexchange. The accepted answer states that commands to the local instance executes on return while multi-line commands to the server executes on semicolon.

Upvotes: 2

Related Questions