Tokens

The basic syntactical units of the SQL language are called tokens. A token consists of one or more characters of which none are blanks, control characters, or characters within a string constant or delimited identifier.

Tokens are classified as ordinary or delimiter tokens:

  • An ordinary token is a numeric constant, an ordinary identifier, a host identifier, or a keyword.
    Examples:
        1        .1        +2        SELECT        E        3
  • A delimiter token is a string constant, a delimited identifier, an operator symbol, or any of the special characters shown in the syntax diagrams. A question mark (?) is also a delimiter token when it serves as a parameter marker, as explained in PREPARE.
    Examples:
        ,        'string'        "fld1"        =        .

Spaces

A space is a sequence of one or more blank characters.

Control characters

A control character is a special character that is used for string alignment. Treated similar to a space, a control character does not cause a particular action to occur. The following table shows the control characters that DB2® recognizes and their hexadecimal values.

Start of change
Table 1. Hexadecimal values for the control characters that DB2 recognizes
Control character EBCDIC hex value UTF-8 hex value UTF-16 hex value
Tab 05 09 U+0009
Form feed 0C 0C U+000C
Carriage return 0D 0D U+000D
New line 15 C285 U+0085
Line feed 25 0A U+000A
DBCS space - - U+3000
End of change

Tokens, other than string constants and certain delimited identifiers, must not include a control character or space. A control character or space can follow a token. A delimiter token, control character, or a space must follow every ordinary token. If the syntax does not allow a delimiter token to follow an ordinary token, a control character or a space must follow that ordinary token.

Comments

Dynamic SQL statements can include SQL comments. Static SQL statements can include host language comments or SQL comments. Comments can be specified wherever a space can be specified, except within a delimiter token or between the keywords EXEC and SQL. In Java, SQL comments are not allowed within embedded Java expressions. There are two types of SQL comments:
simple comments
Simple comments are introduced with two consecutive hyphens (--). Simple comments cannot continue past the end of the line. For additional information, see SQL comments.
bracketed comments
Bracketed comments are introduced with /* and end with */. A bracketed comment can continue past the end of the line. For additional information, see SQL comments.

Uppercase and lowercase

A token in an SQL statement can include lowercase letters, but lowercase letters in an ordinary token are folded to uppercase. However, lowercase letters are folded to uppercase in a C or Java program only if the appropriate precompiler option is specified. Delimiter tokens are never folded to uppercase.

Example: The following two statements, after folding, are equivalent:
   select * from DSN8A10.EMP where lastname = 'Smith';
   SELECT * FROM DSN8A10.EMP WHERE LASTNAME = 'Smith';