Sub topic 5
Removing Padding with the FM Format Modifier
Prerequisites
This chapter assumes that you know basic SELECT syntax and understand Oracle DATE, NUMBER, and VARCHAR2 values. You should also know that TO_CHAR converts a date or number into text by using a format model.
What FM Does
Oracle often adds blank characters to formatted output. It does this so values have a consistent width in reports. For example, the Day and Month elements reserve space for the longest possible day or month name.
The FM modifier means fill mode. It removes padding blanks from the result. It is part of the format model, so place it before the format elements whose padding you want to remove.
| Format model | Result characteristic |
|---|---|
| `Day, DD Month YYYY` | Names are padded to fixed widths |
| `FMDay, DD Month YYYY` | Padding blanks are removed |
| `9,999,999.00` | A leading sign position can produce a blank |
| `FM9,999,999.00` | Leading and trailing padding blanks are removed |
Removing Padding from Dates
The following query formats a date with and without FM:
SELECT TO_CHAR(
DATE '2026-11-28',
'Day, DD Month YYYY',
'NLS_DATE_LANGUAGE=ENGLISH'
) AS padded_date,
TO_CHAR(
DATE '2026-11-28',
'FMDay, DD Month YYYY',
'NLS_DATE_LANGUAGE=ENGLISH'
) AS trimmed_date
FROM dual;The first format reserves space for the longest day and month names. Its result can contain extra blanks after Saturday or November. The second format returns text like:
Saturday, 28 November 2026The DD element still formats the day as a two-digit value. FM removes fill padding, but it does not remove the digit required by the format element.
Use FM when the result will be displayed to users, placed in a message, or compared with text whose spaces matter.
Removing Padding from Numbers
Number format models can also produce padding. A number format reserves space for a possible sign, so a positive number can begin with a blank.
SELECT TO_CHAR(1234567.891, '9,999,999.00') AS padded,
TO_CHAR(1234567.891, 'FM9,999,999.00') AS trimmed,
TO_CHAR(0.5, 'FM990.00') AS leading_zero
FROM dual;The 9 elements allow digits in those positions. The commas group thousands, and .00 requires exactly two digits after the decimal point. The FM version removes the leading blank. The last expression returns 0.50.
FM does not change the value or perform rounding differently. The format model still controls rounding. It changes the text layout produced by TO_CHAR.
Using FM Selectively
You can place FM before a section of a format model. This lets you control which parts use fill mode. In most application output, placing FM at the beginning is simplest and makes the whole formatted result compact.
Use a normal padded model when fixed-width columns are useful, such as a legacy report. Use FM when spaces would make labels, filenames, or exported values difficult to read.
How the Pieces Fit
Check the exact output in your SQL client. Some clients display trailing spaces invisibly, while functions such as LENGTH reveal them.
SELECT LENGTH(TO_CHAR(DATE '2026-11-28',
'Day, DD Month YYYY',
'NLS_DATE_LANGUAGE=ENGLISH')) AS padded_length,
LENGTH(TO_CHAR(DATE '2026-11-28',
'FMDay, DD Month YYYY',
'NLS_DATE_LANGUAGE=ENGLISH')) AS trimmed_length
FROM dual;Exercise
Which format model should you use to return the text 42.50 without a leading blank from the number 42.5: '999.00' or 'FM999.00'?
Show answer
Use 'FM999.00'. FM removes the leading fill blank, while .00 keeps exactly two decimal places.