Sub topic 2
Removing padding with FM, NLS settings, and parsing with TO_DATE and TO_NUMBER
This chapter assumes you know basic SELECT, WHERE, and ORDER BY syntax, the NUMBER, VARCHAR2, and DATE types, and the DUAL table. You should be able to run SQL in SQL*Plus or SQL Developer.
Removing padding with FM
Oracle pads formatted numbers and dates. A number format reserves a column for the sign, and day and month names are padded to the width of the longest name. The FM modifier removes that padding.
SELECT TO_CHAR(1234567.891, '9,999,999.00') AS padded,
TO_CHAR(1234567.891, 'FM9,999,999.00') AS trimmed
FROM dual;The padded column starts with a space. The trimmed column returns 1,234,567.89.
Language and separators: NLS settings and nlsparam
NLS (National Language Support) settings control language, decimal separators, and date formats. Each session has defaults. Code that relies on them can break when another user runs it under different settings. Name the settings in the call instead.
The third argument of TO_DATE sets the language for month names:
SELECT TO_DATE('15-JAN-2026', 'DD-MON-YYYY', 'NLS_DATE_LANGUAGE=ENGLISH') AS parsed
FROM dual;Parsing strings with TO_DATE
TO_DATE turns a string into a DATE value. The format model must match the input element by element. A mismatch raises ORA-01843 (not a valid month) or similar errors.
SELECT TO_DATE('28-11-2026 14:30', 'DD-MM-YYYY HH24:MI') AS parsed
FROM dual;Parsing strings with TO_NUMBER
TO_NUMBER converts a string to a NUMBER. Use G and D in the model for locale group and decimal separators, and set them with nlsparam. Both calls below return 1234.56:
SELECT TO_NUMBER('1,234.56', '9,999.99') AS us_style,
TO_NUMBER('1.234,56', '9G999D99', 'NLS_NUMERIC_CHARACTERS='',.''') AS eu_style
FROM dual;Exercise
What does SELECT TO_CHAR(0.5, 'FM990.00') FROM dual; return?
Show answer
It returns '0.50'. The FM modifier removes the leading blank, and the 0 in the model forces a leading zero before the decimal point.