6.1.2 Rules for separators
- Organization of this subsection
(1) About separators
When writing SQL statements, you need to put separators between two keywords, or between keywords and names, and so on. Separators include the following:
-
Spaces
The following white space characters are treated as spaces:
-
Space
-
CR (carriage return): Return
-
NL (new line): Line break
-
Tab
-
-
Comments
(2) Where separators must be inserted
Separators must be inserted in the following places:
-
Between two keywords
-
Between a keyword and a name
-
Between two names
-
Between a keyword and a numeric value
-
Between a name and a numeric value
Examples of where separators must be inserted are shown in the following figure.
(3) Where separators cannot be inserted
Separators cannot be inserted in the following places:
-
Inside a keyword
-
Inside a name that is not enclosed in double quotation marks (")
-
After the opening double quotation mark (") that encloses a name
-
Before the closing double quotation mark (") that encloses a name
-
Inside a numeric literal (except after the sign specified at the beginning)
-
Between the X and the following ' in the hexadecimal-format binary literal representation X'...'
-
Between the B and the following ' in the binary-format binary literal representation B'...'
-
Inside an operator (inside a comparison operator consisting of two characters)
Examples of where separators cannot be inserted are shown in the following figure.
(4) Where separators can be inserted
Separators can be inserted in the following places:
-
In places not prohibited under (3) Where separators cannot be inserted above, as well as before and after the following special characters:
, . -+ * '" ( )< > = ^ ! ? tab NL CR space
Examples of where separators can be inserted are shown in the following figure.
(5) Comments
You can add a comment at any location in an SQL statement where a separator can be inserted. Comments are illustrated in the example below.
- Example
-
SELECT "C1","C2" FROM "T1" /* comment1 */ ORDER BY "C1" ASC /* comment2 */
The underlined portions are comments. Everything between the /* and the */ is considered part of the comment.
When writing comments, the following guidelines must be observed:
-
A comment cannot be placed inside an identifier or character string literal.
-
Comments cannot be nested.
Example
SELECT * FROM "T1" /* /* comment1 */ comment2 */
Specifying nested comments as shown above results in a syntax error.
-
If the /* and */ are enclosed in double quotation marks (") or single quotation marks ('), they are not treated as defining a comment.
Example
SELECT * FROM "T1" WHERE "C1"='/* comment */'
The underlined portion above is treated as a character string literal rather than a comment.
-
Note that a character string that begins with /*>> and ends with <<*/ is not treated as a comment.
Example
SELECT * FROM "T1" /*>> WITHOUT INDEX <<*/
In the preceding example, the underlined portion is treated as an index specification rather than a comment. For details about index specifications, see 7.14 Index specification.
However, a comment can appear within the index specification enclosed in /*>> and <<*/.
Example
SELECT * FROM "T1" /*>> WITHOUT INDEX /* WITH INDEX(INDEXNAME)*/ <<*/
The underlined portion above is treated as a comment. When processed, it is equivalent to the following SQL statement:
SELECT * FROM "T1" /*>> WITHOUT INDEX <<*/
-
Note that a character string that begins with /*>> and ends with <<*/ cannot be specified within a comment. For example, it is impossible to include an index specification in a comment.
Example
SELECT * FROM "T1" /* /*>> WITHOUT INDEX <<*/ */
In the preceding example, an index specification (the underlined portion) appears within a comment. Therefore, this SQL statement results in a syntax error.