A constant (also called a literal) specifies a value. Constants are classified as string constants or numeric constants. String constants are further classified as character or graphic. Numeric constants are further classified as integer, floating point, or decimal.
All constants have the attribute NOT NULL. A negative sign in a numeric constant with a value of zero is ignored.
An integer constant specifies an integer as a signed or unsigned number with a maximum of 19 digits that does not include a decimal point. The data type of an integer constant is large integer if its value is within the range of a large integer. The data type of an integer constant is big integer if its value is outside the range of a large integer, but within the range of a big integer. A constant that is defined outside the range of big integer values is considered a decimal constant.
64 -15 +100 32767 720176 12345678901
In syntax diagrams, the term integer is used for a large integer constant that must not include a sign.
A floating-point constant specifies a double-precision floating-point number as two numbers separated by an E. The first number can include a sign and a decimal point; the second number can include a sign but not a decimal point. The value of the constant is the product of the first number and the power of 10 specified by the second number; it must be within the range of floating-point numbers. The number of characters in the constant must not exceed 24. Excluding leading zeros, the number of digits in the first number must not exceed 17 and the number of digits in the second must not exceed 3.
15E1 2.E5 2.2E-1 +5.E+2
A decimal constant specifies a decimal number as a signed or unsigned number that consists of no more than 63 digits. The constant must either:
The precision is the total number of digits (including leading and trailing zeros); the scale is the number of digits to the right of the decimal point (including trailing zeros).
If the precision of the decimal constant is greater than the largest decimal precision and the scale is not greater than the largest decimal precision, then leading zeroes to the left of the decimal point are eliminated to reduce the precision to the largest decimal precision.
25.5 1000. -15. +37589.3333333333 12345678901
A character-string constant specifies a varying-length character string. The two forms of character-string constant follow:
Character-string constants can contain mixed data. If the job CCSID supports mixed data, a character-string constant is classified as mixed data if it includes a DBCS substring. In all other cases, a character-string constant is classified as SBCS data.
The CCSID assigned to the constant is the CCSID of the source containing the constant unless the source is encoded in a foreign encoding scheme (such as ASCII). The data in the variable is converted from the foreign encoding scheme to the default CCSID of the current server. In this case, the CCSID assigned to the constant is the default CCSID of the current server.
The CCSID of the source is determined by the application requester. The CCSID of the source is:
Character-string constants are used to represent constant datetime values in assignments and comparisons. For more information see String representations of datetime values.
'Peggy' '14.12.1990' '32' 'DON''T CHANGE' '' X'FFFF'
A graphic-string constant is a varying-length graphic string. The length of the specified string cannot be greater than 16370. The three forms of DBCS graphic-string constants are:
In the normal form, the SQL delimiters and the G or the N are SBCS characters. The SBCS ' is the EBCDIC apostrophe, X'7D'.
In the PL/I form, the apostrophes and the G are DBCS characters. Two consecutive DBCS string delimiters are used to represent one string delimiter within the string. Note that this PL/I form is only valid for static statements embedded in PL/I programs.
A hexadecimal DBCS graphic constant is also supported. The form of the hexadecimal DBCS graphic constant is:
GX'ssss'
In the constant, ssss represents a string from 0 to 32760 hexadecimal digits. The number of characters between the string delimiters must be an even multiple of 4. Blanks between the string delimiters are ignored. Each group of 4 digits represents a single DBCS graphic character. The hexadecimal for shift-in and shift-out ('0E'X and '0F'X) are not included in the string.
The CCSID assigned to constants is the DBCS CCSID associated with the CCSID of the source unless the source is encoded in a foreign encoding scheme (such as ASCII). In this case, the CCSID assigned to the constant is the DBCS CCSID associated with the default CCSID of the current server when the SQL statement containing the constant is prepared. If there is no DBCS CCSID associated with the CCSID of the source, the CCSID is 65535.
For information on associated DBCS CCSIDs, see the Globalization DBCS CCSIDs topic in the iSeries Information Center. For information on the CCSID of the source, see Character String Constants.
A hexadecimal UTF-16 (or UCS-2) graphic constant is supported. The form of the hexadecimal UTF-16 graphic constant is:
UX'ssss'
In the constant, ssss represents a string from 0 to 32760 hexadecimal digits. The number of characters between the string delimiters must be an even multiple of 4. Blanks between the string delimiters are ignored. Each group of 4 or more digits represents a single UTF-16 graphic character.
The CCSID of a UTF-16 constant is 1200.
A binary-string constant specifies a varying-length binary string. The form of a binary-string constant follows:
The CCSID assigned to the constant is 65535.
Note that the syntax of a binary string constant is identical to the second form of a character constant. A constant of this form is only treated as a binary string constant if:
X'FFFF'
A datetime constant specifies a date, time, or timestamp. Typically, character-string constants are used to represent constant datetime values in assignments and comparisons. However, the ANSI/ISO SQL standard form of a datetime constant can be used to specifically denote the constant as a datetime constant instead of a character-string constant. For more information see String representations of datetime values.
DATE '2003-09-03'
The default decimal point can be specified:
The default decimal point can be specified through the following interfaces:
SQL Interface | Specification |
---|---|
Embedded SQL | The *JOB, *PERIOD, *COMMA, or *SYSVAL value
in the OPTION parameter is specified on the Create SQL Program (CRTSQLxxx)
commands. The SET OPTION statement can also be used to specify the DECMPT
parameter within the source of a program containing embedded SQL.
|
Interactive SQL and Run SQL Statements | The DECPNT parameter on the Start SQL (STRSQL)
command or by changing the session attributes. The DECMPT parameter on the
Run SQL Statements (RUNSQLSTM) command.
|
Call Level Interface (CLI) on the server | SQL_ATTR_DATE_FMT and SQL_ATTR_DATE_SEP environment
or connection variables
|
JDBC or SQLJ on the server using IBM® Developer Kit for Java | Decimal Separator conneciton property
|
ODBC on a client using the iSeries Access Family ODBC Driver | Decimal Separator in the Advanced Server
Options in ODBC Setup
|
JDBC on a client using the IBM Toolbox for Java | Format in JDBC Setup
|
If the comma is the decimal point, the following rules apply:
Thus, to specify a decimal constant without a fractional part, the trailing comma must be followed by a non-blank character. The non-blank character can be a separator comma, as in:
VALUES(9999999999,, 111)
*APOST and *QUOTE are mutually exclusive COBOL precompiler options that name the string delimiter within COBOL statements. *APOST names the apostrophe (') as the string delimiter; *QUOTE names the quotation mark ("). *APOSTSQL and *QUOTESQL are mutually exclusive COBOL precompiler options that play a similar role for SQL statements embedded in COBOL programs. *APOSTSQL names the apostrophe (') as the SQL string delimiter; with this option, the quotation mark (") is the SQL escape character. *QUOTESQL names the quotation mark as the SQL string delimiter; with this option, the apostrophe is the SQL escape character. The values of *APOSTSQL and *QUOTESQL are respectively the same as the values of *APOST and *QUOTE.
In host languages other than COBOL, the usages are fixed. The string delimiter for the host language and for static SQL statements is the apostrophe ('); the SQL escape character is the quotation mark (").