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.
(1)
Constant Expressions

1  %Quoted String1
1  %Literal Number2
2.2.1 USER
2.2.1 CURRENT_USER
2.1 3
2.2.1 CURRENT_ROLE
2.2.1 DEFAULT_ROLE3
2.2.1 SITENAME
2.2.1 DBSERVERNAME
2.1 TODAY
2.1 
2.2.1 CURRENT
2.2.1 SYSDATE
2.1?   precision 
2.1  %Literal DATETIME4
2.1  %Literal INTERVAL5
2.1  num UNITS time_unit
2.2.1 ?   owner  . 
2.2.2.1  sequence 
2.2.2.1  synonym 
2.2.1  . 
2.2.2.1 CURRVAL
2.2.2.1 NEXTVAL
2.2.1  %Literal Collection6
2.2.1  %Literal Row7
2.2.1 literal opaque type
2.2.1 literal BOOLEAN
Notes:
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.