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" = .
A space is a sequence of one or more blank 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.
|Control character||EBCDIC hex value||UTF-8 hex value||UTF-16 hex value|
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.
The left bracket ([) and right bracket (]) characters are used in syntax to refer to an array element. Those characters cannot be specified with some CCSIDs. The following trigraphs can be used as an alternative way to specify left and right brackets:
- The string ??( can be specified in place of a left bracket ([).
- The string ??) can be specified in place of a right bracket (]).
- 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.
select * from DSN8B10.EMP where lastname = 'Smith';
SELECT * FROM DSN8B10.EMP WHERE LASTNAME = 'Smith';