Reputation: 277
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
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