ALTER SESSION

更新时间:
复制 MD 格式

Sets a runtime parameter for the current session. ALTER SESSION only changes the value that is used by the current session.

Syntax

ALTER SESSION SET name = value

Parameters

ParameterDescription
nameThe name of the runtime parameter to set.
valueThe new value for the parameter.

Supported parameters

PolarDB for PostgreSQL (Compatible with Oracle) supports the following ALTER SESSION parameters. Parameters fall into two categories: those that change runtime behavior, and those accepted for Oracle syntax compatibility but have no effect.

Parameters that take effect

ParameterTypeValid valuesDefaultDescription
NLS_DATE_FORMATstringSets the date format for displaying date and time values and for interpreting ambiguous data input values. Has the same effect as the PostgreSQL datestyle parameter.
NLS_LANGUAGEstringSets the language for system messages. Has the same effect as the PostgreSQL lc_messages parameter. The value must use the PostgreSQL locale format (for example, en_US.UTF-8), not the Oracle language name format.
OPTIMIZER_MODEstringALL_ROWS, CHOOSE, FIRST_ROWS, FIRST_ROWS_10, FIRST_ROWS_100, FIRST_ROWS_1000CHOOSESets the default query optimizer mode.

Syntax-compatibility parameters (no effect)

The following parameters are accepted to maintain Oracle syntax compatibility but do not change runtime behavior in PolarDB for PostgreSQL (Compatible with Oracle).

ParameterTypeValid valuesDefault
NLS_LENGTH_SEMANTICSstringBYTE, CHARBYTE
QUERY_REWRITE_ENABLEDstringTRUE, FALSE, FORCEFALSE
QUERY_REWRITE_INTEGRITYstringENFORCED, TRUSTED, STALE_TOLERATEDENFORCED

Examples

Set the session language to English (United States) with UTF-8 encoding:

ALTER SESSION SET NLS_LANGUAGE = 'en_US.UTF-8';
The locale value en_US.UTF-8 uses the PostgreSQL format, not the Oracle language name format. This format is not compatible with Oracle databases.

Set the date display format to day/month/year:

ALTER SESSION SET NLS_DATE_FORMAT = 'dd/mm/yyyy';