Oracle database sql language reference number format models

This chapter presents the format models for datetime and number data stored in character strings.

This chapter includes the following sections:

Overview of Format Models

A format model is a character literal that describes the format of DATETIME or NUMBER data stored in a character string. When you convert a character string into a datetime or number, a format model tells Oracle how to interpret the string.

Oracle Database SQL Language Reference for more information on format models

Number Format Models

You can use number format models:

Number Format Elements

A number format model is composed of one or more number format elements. The following table lists the elements of a number format model.

Table 7-1 Number Format Elements

Returns a comma in the specified position. You can specify multiple commas in a number format model.

Returns a decimal point, which is a period (.) in the specified position.

Restriction: You can specify only one period in a number format model.

Returns value with a leading dollar sign.

Returns leading zeros.

Returns trailing zeros.

Returns value with the specified number of digits with a leading space if positive or with a leading minus if negative. Leading zeros are blank, except for a zero value, which returns a zero for the integer part of the fixed-point number.

Returns blanks for the integer part of a fixed-point number when the integer part is zero (regardless of zeros in the format model).

Returns in the specified position the ISO currency symbol (the current value of the NLS_ISO_CURRENCY parameter).

Returns in the specified position the decimal character, which is the current value of the NLS_NUMERIC_CHARACTER parameter. The default is a period (.).

Restriction: You can specify only one decimal character in a number format model.

Returns a value using in scientific notation.

Returns in the specified position the group separator (the current value of the NLS_NUMERIC_CHARACTER parameter). You can specify multiple group separators in a number format model.

Restriction: A group separator cannot appear to the right of a decimal character or period in a number format model.

Returns in the specified position the local currency symbol (the current value of the NLS_CURRENCY parameter).

Returns negative value with a trailing minus sign (-).

Returns positive value with a trailing blank.

Restriction: The MI format element can appear only in the last position of a number format model.

Returns negative value in .

Returns positive value with a leading and trailing blank.

Restriction: The PR format element can appear only in the last position of a number format model.

Returns a value as Roman numerals in uppercase.

Returns a value as Roman numerals in lowercase.

Value can be an integer between 1 and 3999.

Returns negative value with a leading minus sign (-).

Returns positive value with a leading plus sign (+).

Returns negative value with a trailing minus sign (-).

Returns positive value with a trailing plus sign (+).

Restriction: The S format element can appear only in the first or last position of a number format model.

The text minimum number format model returns (in decimal output) the smallest number of characters possible. This element is case insensitive.

The default is TM9, which returns the number in fixed notation unless the output exceeds 64 characters. If the output exceeds 64 characters, then Oracle Database automatically returns the number in scientific notation.

Returns in the specified position the Euro (or other) dual currency symbol, determined by the current value of the NLS_DUAL_CURRENCY parameter.

Returns a value multiplied by 10 n (and if necessary, round it up), where n is the number of 9's after the V .

Returns the hexadecimal value of the specified number of digits. If the specified number is not an integer, then Oracle Database rounds it to an integer.

Oracle Database SQL Language Reference for more information on number format models

Datetime Format Models

You can use datetime format models:

Datetime Format Elements

A datetime format model is composed of one or more datetime format elements. The following table lists the elements of a date format model.

Table 7-2 Datetime Format Elements

- / , . ; : "text"

Punctuation and quoted text is reproduced in the result.

AD A.D.

AD indicator with or without periods.

AM A.M.

Meridian indicator with or without periods.

BC B.C.

BC indicator with or without periods.

CC SCC

For example, 2002 returns 21; 2000 returns 20.

Day of week (1-7). This element depends on the NLS territory of the session.

Day of month (1-31).

Day of year (1-366).

Returns a value in the long date format, which is an extension of Oracle Database's DATE format, determined by the current value of the NLS_DATE_FORMAT parameter. Makes the appearance of the date components (day name, month number, and so forth) depend on the NLS_TERRITORY and NLS_LANGUAGE parameters. For example, in the AMERICAN_AMERICA locale, this is equivalent to specifying the format 'fmDay, Month dd, yyyy' . In the GERMAN_GERMANY locale, it is equivalent to specifying the format ' fmDay, dd. Month yyyy '.

Restriction: You can specify this format only with the TS element, separated by white space.

Returns a value in the short date format. Makes the appearance of the date components (day name, month number, and so forth) depend on the NLS_TERRITORY and NLS_LANGUAGE parameters. For example, in the AMERICAN_AMERICA locale, this is equivalent to specifying the format ' MM/DD/RRRR '. In the ENGLISH_UNITED_KINGDOM locale, it is equivalent to specifying the format ' DD/MM/RRRR '.

Restriction: You can specify this format only with the TS element, separated by white space.

Abbreviated name of day.

Abbreviated era name (Japanese Imperial, ROC Official, and Thai Buddha calendars).

Full era name (Japanese Imperial, ROC Official, and Thai Buddha calendars).

FF [1..9]

Fractional seconds; no radix character is printed. Use the X format element to add the radix character. Use the numbers 1 to 9 after FF to specify the number of digits in the fractional second portion of the datetime value returned. If you do not specify a digit, then Oracle Database uses the precision specified for the datetime data type or the data type's default precision. Valid in timestamp and interval formats, but not in DATE formats.

SELECT TO_CHAR(SYSTIMESTAMP, 'SS.FF3') from dual;

Returns a value with no leading or trailing blanks.

See Also : Oracle Database SQL Language Reference for more information on the FM format model modifier

Requires exact matching between the character data and the format model.

See Also : Oracle Database SQL Language Reference for more information on the FX format model modifier

HH HH12

Hour of day (1-12).

HH24

Hour of day (0-23).

Week of year (1-52 or 1-53) based on the ISO standard.

IYY IY I

Last 3, 2, or 1 digit(s) of ISO year.

IYYY

4-digit year based on the ISO standard.

Julian day; the number of days since January 1, 4712 BC. Number specified with J must be integers.