Sub topic 5
Removing Padding with FM
This chapter assumes you can already call TO_CHAR with a date or number format model, as covered in the earlier chapters on formatting dates and numbers. Here you will learn what the FM modifier does, why it exists, and where it can surprise you.
Where the padding comes from
TO_CHAR returns a VARCHAR2 string, and by default Oracle pads that string so that results line up in columns. Two kinds of padding appear:
- Trailing blanks on names.
Daypads to 9 characters, the length of "Wednesday".Monthalso pads to 9, the length of "September". "Saturday" and "November" therefore each get one trailing blank, and "March" gets four. - Leading characters on numbers. Every number result reserves one leading position for a sign, so a positive number starts with a blank. Digit positions written as
9that the value does not need are also filled with blanks.
This padding is useful in a fixed-width report. It is a nuisance when you concatenate the result into a sentence, write it to a CSV file, or compare it with another string.
SELECT LENGTH(TO_CHAR(DATE '2026-11-28', 'Day')) AS day_padded,
LENGTH(TO_CHAR(DATE '2026-11-28', 'FMDay')) AS day_fm,
LENGTH(TO_CHAR(5, '999')) AS num_padded,
LENGTH(TO_CHAR(5, 'FM999')) AS num_fm
FROM dual;The four columns return 9, 8, 4, and 1. The value 5 formatted with 999 is three digit positions plus the sign position, so it is four characters long.
The FM modifier ("fill mode") turns this padding off. You put it at the start of the format model, or in front of any single element.
FM with dates
For dates, FM removes two things:
- Trailing blanks after names such as
DayandMonth. - Leading zeros on numeric elements such as
DD,MM,HH24, andMI.
The second effect is easy to overlook. The spine example uses FM to tidy up a long date, and the same model also changes the day number.
SELECT 'Due ' || TO_CHAR(DATE '2026-03-05', 'Day, DD Month YYYY') AS padded,
'Due ' || TO_CHAR(DATE '2026-03-05', 'FMDay, DD Month YYYY') AS trimmed
FROM dual;With English day and month names, the results are:
| Column | Result |
|---|---|
| `padded` | `Due Thursday , 05 March 2026` |
| `trimmed` | `Due Thursday, 5 March 2026` |
The padded version has a blank before the comma and five blanks between "March" and "2026". The trimmed version has neither, and the day is 5 instead of 05.
The table below shows each element for 5 March 2026 at 07:05.
| Element | Without FM | With FM |
|---|---|---|
| `DD` | `05` | `5` |
| `MM` | `03` | `3` |
| `Month` | `March` followed by 4 blanks | `March` |
| `Day` | `Thursday` followed by 1 blank | `Thursday` |
| `HH24` | `07` | `7` |
| `MI` | `05` | `5` |
| `YYYY` | `2026` | `2026` |
YYYY does not change because a four-digit year has no leading zeros to remove.
FM is a toggle
FM does not apply to the whole model once and for all. Each FM you write switches fill mode on if it is off, and off if it is on. An element is affected by whichever state is in force when Oracle reaches it.
This matters for times. FMHH24:MI would give 7:5 for 07:05, which is not a readable time. If you toggle FM off again before MI, the minutes keep their leading zero.
SELECT TO_CHAR(TO_DATE('2026-03-05 07:05', 'YYYY-MM-DD HH24:MI'),
'FMHH24:MI') AS all_trimmed,
TO_CHAR(TO_DATE('2026-03-05 07:05', 'YYYY-MM-DD HH24:MI'),
'FMHH24:FMMI') AS hours_only_trimmed
FROM dual;The results are 7:5 and 7:05.
The diagram shows the state Oracle is in as it reads a model such as FMDD-FMMM-YYYY.
For example, in FMDD-FMMM-YYYY the first FM switches trimming on, so DD loses its zero. The second FM switches it off again, so MM keeps its zero. For 5 March 2026 the result is 5-03-2026.
SELECT TO_CHAR(DATE '2026-03-05', 'FMDD-FMMM-YYYY') AS toggled
FROM dual;The usual style is a single FM at the front. Use a second one only when you need part of the string to stay padded, as with FMHH24:FMMI.
FM with numbers
For numbers, FM removes the blank sign position at the front, plus other padding that depends on how you wrote the model:
- Digit positions written as
9are dropped if they are not needed, both before and after the decimal point. - Digit positions written as
0always print, so they keep leading and trailing zeros.
That second rule is how you control the shape of the output. The spine example uses both ideas.
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 padded column is 1,234,567.89, with one leading blank for the sign. The trimmed column is 1,234,567.89. The leading_zero column is 0.50. The value is rounded to two decimals because the model has two digit positions after the point.
The next table shows how 9 and 0 behave under FM.
| Format model | Value | Result |
|---|---|---|
| `FM999` | `5` | `5` |
| `FM9,999.00` | `1234.5` | `1,234.50` |
| `FM9,999.99` | `1234.5` | `1,234.5` |
| `FM99.99` | `0.5` | `.5` |
| `FM990.00` | `0.5` | `0.50` |
| `FM99.99` | `12` | `12.` |
Notice the last two kinds of surprise:
- With
9after the decimal point, trailing zeros disappear, so1234.5loses its second decimal. - With
9before the decimal point, the leading zero in0.5disappears, which gives.5.
Use 0 where you want a digit to always appear, and 9 where you want it to appear only when needed. For prices, FM9,999,990.00 is a common model. It always shows at least one integer digit and exactly two decimals.
A model such as FM$9,999,990.00 also adds a currency symbol. The $ goes after FM and applies to the number.
Gotchas
- A trailing decimal point.
FM99.99formatting12returns12., because the point is part of the model and no fractional digits follow it. If the value can be whole, prefer0after the point, as inFM99.00. - Overflow is not fixed by FM. If the number has more digits than the model allows, Oracle returns a string of
#characters.FMremoves padding. It does not widen the model, so make the model wide enough for the largest value you expect. - Parsing does not need FM. By default
TO_DATE('5-3-2026', 'DD-MM-YYYY')accepts missing leading zeros, so you do not addFMto make input more tolerant.FMbelongs inTO_CHARoutput. It only matters in input when you request exact matching with theFXmodifier, which is outside this chapter. - The result is text. After
TO_CHAR(..., 'FM...')you have aVARCHAR2. Sorting these strings sorts them as text, so'10'comes before'9'. Keep the originalDATEorNUMBERforORDER BYand arithmetic, and use the formatted string only for display. - Language still applies.
FMremoves padding but does not translate names.DayandMonthuseNLS_DATE_LANGUAGE, so output such asThursdayassumes an English session. Pass'NLS_DATE_LANGUAGE=ENGLISH'as the third argument ofTO_CHARif the text must not vary. - Fixed-width reports are the exception. If you want columns aligned in plain-text output, the padding is helping you. Leave
FMout there.
Exercises
Exercise
What does TOCHAR(TODATE('2026-03-05 07:05', 'YYYY-MM-DD HH24:MI'), 'FMDD/MM/YYYY HH24:FMMI') return, and why?
Show answer
It returns 5/3/2026 7:05. The first FM switches fill mode on, so DD, MM, and HH24 lose their leading zeros (5, 3, and 7). YYYY has no leading zero to remove. The second FM, placed before MI, switches fill mode off again, so the minutes stay as 05.
Exercise
Write a TO_CHAR call that shows 1234.5 as $1,234.50 with no leading blank, and show a value that the same model prints as $0.00 when the input is 0.
Show answer
SELECT TOCHAR(1234.5, 'FM$9,999,990.00') AS price, TOCHAR(0, 'FM$9,999,990.00') AS zero_price FROM dual; The FM removes the sign blank. The 0 before the decimal point and the two 0 digits after it force at least one integer digit and exactly two decimals, so the results are $1,234.50 and $0.00.