Constant Expressions
Certain expressions that return a fixed value are called constant expressions. These include variant function operators that read the system clock, but that are valid in contexts where literal constants are also valid.
Among these expressions are the following operators (or system
constants) whose returned values are determined at runtime:
- CURRENT returns the current time and date from the system clock.
- CURRENT_ROLE returns the name of the role, if any, whose privileges are enabled for the current user.
- CURRENT_USER is a synonym for USER.
- DEFAULT_ROLE returns the name of the role, if any, that is the default role for the current user.
- DBSERVERNAME returns the name of the current database server.
- SITENAME is a synonym for DBSERVERNAME.
- SYSDATE reads the DATETIME value from the system clock like the CURRENT operator, but has a different default precision.
- TODAY returns the current calendar date from the system clock.
- USER returns the login name (also called the authorization identifier) of the current user.
Besides these operators, the term constant expression can also refer to a quoted string, to a literal value, or to the UNITS operator with its operands.
The Constant Expression segment
has the following syntax.
Element | Description | Restrictions | Syntax |
---|---|---|---|
literal Boolean | Literal representation of a BOOLEAN value | Must be either t (TRUE) or f (FALSE) | Quoted String |
literal opaque type | Literal representation of value of an opaque data type | Must be recognized by the input support function of opaque type | Defined by UDT developer |
num | How many of specified time units. See UNITS Operator. | If num is not an integer, the fractional part is truncated | Literal Number |
owner | Name of the owner of sequence | Must own sequence | Owner name |
precision | Precision of the returned DATETIME expression | On Windows™ systems the maximum scale of seconds is FRACTION(3). | DATETIME Field Qualifier |
sequence | Name of a sequence | Must exist in current database | Identifier |
synonym | Synonym for the name of a sequence | Must exist in current database | Identifier |
time_unit | Keyword to specify time unit: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, or FRACTION | Must be one of the keywords at left. Case insensitive but cannot be enclosed within quotes | See the Restrictions column. |