0% found this document useful (0 votes)
8 views

FormatModels CheatSheet

Uploaded by

chanduvenu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

FormatModels CheatSheet

Uploaded by

chanduvenu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Cheat Sheet: Format Models

NUMBER FORMAT ELEMENTS: ............................................................................................ 1


DATETIME FORMAT ELEMENTS ........................................................................................... 3
FORMAT MODEL MODIFIERS: .............................................................................................. 7
FM ........................................................................................................................... 7
FX ............................................................................................................................ 8

Number Format Elements:


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

Restrictions:

A comma element cannot begin a number format model.

A comma cannot appear to the right of a decimal character or period in a number format
model.
, (comma) 9,999
Returns a decimal point, which is a period (.) in the specified position.

. (period) 99.99 Restriction: You can specify only one period in a number format model.
$ $9999 Returns value with a leading dollar sign.
0999 Returns leading zeros.

0 9990 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
9 9999 integer part of the fixed-point number.
Returns blanks for the integer part of a fixed-point number when the integer part is zero
B B9999 (regardless of zeros in the format model).
Returns in the specified position the ISO currency symbol (the current value of the
C C999 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 (.).

D 99D99 Restriction: You can specify only one decimal character in a number format model.
EEEE 9.9EEEE 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
G 9G999 number format model.

sql.standout-dev.com
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
L L999 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
MI 9999MI model.
Returns negative value in <angle brackets>.

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
PR 9999PR model.
RN RN Returns a value as Roman numerals in uppercase.

rn rn Returns a value as Roman numerals in lowercase.

Value can be an integer between 1 and 3999.


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

9999S 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
S 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.

Restrictions:

You cannot precede this element with any other element.


TM TM

sql.standout-dev.com
You can follow this element only with one 9 or one E (or e), but not with any combination of
these. The following statement returns an error:

SELECT TO_CHAR(1234, 'TM9e') FROM DUAL;

Returns in the specified position the Euro (or other) dual currency symbol, determined by the
U U9999 current value of the NLS_DUAL_CURRENCY parameter.
Returns a value multiplied by 10n (and if necessary, round it up), where n is the number of 9's
V 999V99 after the V.
Returns the hexadecimal value of the specified number of digits. If the specified number is not an
XXXX integer, then Oracle Database rounds it to an integer.

xxxx Restrictions:

This element accepts only positive values or 0. Negative values return an error.

You can precede this element only with 0 (which returns leading zeroes) or FM. Any other
elements return an error. If you specify neither 0 nor FM with X, then the return always has one
leading blank. Refer to the format model modifier FM for more information.
X

Datetime Format Elements:


TO_* datetime
Element Description
functions?
-
/
,
.
;
:
"text"

Yes Punctuation and quoted text is reproduced in the result.


AD
A.D.

Yes AD indicator with or without periods.


AM
A.M.

Yes Meridian indicator with or without periods.


BC
B.C.

Yes BC indicator with or without periods.

sql.standout-dev.com
CC Century.
SCC
If the last 2 digits of a 4-digit year are between 01 and 99 (inclusive), then the century is one
greater than the first 2 digits of that year.

If the last 2 digits of a 4-digit year are 00, then the century is the same as the first 2 digits of
that year.

For example, 2002 returns 21; 2000 returns 20.

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

DAY Yes Name of day.

DD Yes Day of month (1-31).

DDD Yes Day of year (1-366).


Returns a value in the long date format, which is an extension of the Oracle Database 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'.

DL Yes 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'.

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

DY Yes Abbreviated name of day.

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

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

sql.standout-dev.com
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.

Examples: 'HH:MI:SS.FF'

FF [1..9] Yes SELECT TO_CHAR(SYSTIMESTAMP, 'SS.FF3') from DUAL;


Returns a value with no leading or trailing blanks.

See Also: Additional discussion on this format model modifier in the Oracle Database SQL
FM Yes Language Reference
Requires exact matching between the character data and the format model.

See Also: Additional discussion on this format model modifier in the Oracle Database SQL
FX Yes Language Reference
HH
HH12

Yes Hour of day (1-12).

HH24 Yes Hour of day (0-23).


Calendar week of year (1-52 or 1-53), as defined by the ISO 8601 standard.

A calendar week starts on Monday.

The first calendar week of the year includes January 4.

The first calendar week of the year may include December 29, 30, and 31.

The last calendar week of the year may include January 1, 2, and 3.
IW

IYYY 4-digit year of the year containing the calendar week, as defined by the ISO 8601 standard.
IYY
IY
I
Last 3, 2, or 1 digit(s) of the year containing the calendar week, as defined by the ISO 8601
standard.

Julian day; the number of days since January 1, 4712 BC. Number specified with J must be
J Yes integers.
MI Yes Minute (0-59).

sql.standout-dev.com
MM Yes Month (01-12; January = 01).

MON Yes Abbreviated name of month.

MONTH Yes Name of month.


PM
P.M.

Yes Meridian indicator with or without periods.

Q Quarter of year (1, 2, 3, 4; January - March = 1).

RM Yes Roman numeral month (I-XII; January = I).


Lets you store 20th century dates in the 21st century using only two digits.

RR Yes

Round year. Accepts either 4-digit or 2-digit input. If 2-digit, provides the same return as RR. If you
RRRR Yes do not want this functionality, then enter the 4-digit year.

SS Yes Second (0-59).

SSSSS Yes Seconds past midnight (0-86399).


Returns a value in the short time format. Makes the appearance of the time components (hour,
minutes, and so forth) depend on the NLS_TERRITORY and NLS_LANGUAGE initialization
parameters.

Restriction: You can specify this format only with the DL or DS element, separated by white
TS Yes space.
Daylight saving information. The TZD value is an abbreviated time zone string with daylight saving
information. It must correspond with the region specified in TZR. Valid in timestamp and interval
formats, but not in DATE formats.

TZD Yes Example: PST (for US/Pacific standard time); PDT (for US/Pacific daylight time).
Time zone hour. (See TZM format element.) Valid in timestamp and interval formats, but not in
DATE formats.

TZH Yes Example: 'HH:MI:SS.FFTZH:TZM'.


Time zone minute. (See TZH format element.) Valid in timestamp and interval formats, but not in
DATE formats.
TZM Yes

sql.standout-dev.com
Example: 'HH:MI:SS.FFTZH:TZM'.
Time zone region information. The value must be one of the time zone region names supported in
the database. Valid in timestamp and interval formats, but not in DATE formats.

TZR Yes Example: US/Pacific

Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh
WW day of the year.

W Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
Local radix character.

X Yes Example: 'HH:MI:SSXFF'.

Y,YYY Yes Year with comma in this position.


YEAR
SYEAR
Year, spelled out; S prefixes BC dates with a minus sign (-).
YYYY
SYYYY

Yes 4-digit year; S prefixes BC dates with a minus sign.


YYY
YY
Y
Yes Last 3, 2, or 1 digit(s) of year.

Format Model Modifiers:


FM
Fill mode. Oracle uses trailing blank characters and leading zeroes to fill format elements to a constant width. The width is equal to the display
width of the largest element for the relevant format model:

• Numeric elements are padded with leading zeros to the width of the maximum value allowed for the element. For example, the YYYY
element is padded to four digits (the length of '9999'), HH24 to two digits (the length of '23'), and DDD to three digits (the length of '366').
• The character elements MONTH, MON, DAY, and DY are padded with trailing blanks to the width of the longest full month name, the
longest abbreviated month name, the longest full date name, or the longest abbreviated day name, respectively, among valid names
determined by the values of NLS_DATE_LANGUAGE and NLS_CALENDAR parameters. For example, when NLS_DATE_LANGUAGE is
AMERICAN and NLS_CALENDAR is GREGORIAN (the default), the largest element for MONTH is SEPTEMBER, so all values of the
MONTH format element are padded to nine display characters. The values of the NLS_DATE_LANGUAGE and NLS_CALENDAR
parameters are specified in the third argument to TO_CHAR and TO_* datetime functions or they are retrieved from the NLS
environment of the current session.
• The character element RM is padded with trailing blanks to the length of 4, which is the length of 'viii'.
• Other character elements and spelled-out numbers (SP, SPTH, and THSP suffixes) are not padded.
The FM modifier suppresses the above padding in the return value of the TO_CHAR function.

sql.standout-dev.com
FX
Format exact. This modifier specifies exact matching for the character argument and datetime format model of a TO_DATE function:

• Punctuation and quoted text in the character argument must exactly match (except for case) the corresponding parts of the format model.
• The character argument cannot have extra blanks. Without FX, Oracle ignores extra blanks.
• Numeric data in the character argument must have the same number of digits as the corresponding element in the format model. Without
FX, numbers in the character argument can omit leading zeros.

When FX is enabled, you can disable this check for leading zeros by using the FM modifier as well.

If any portion of the character argument violates any of these conditions, then Oracle returns an error message.

sql.standout-dev.com

You might also like