Sub topic 6
Language and separators: NLS settings and nlsparam
This chapter covers the part of conversion that depends on language and locale: month names, decimal and group separators, and currency symbols. It assumes you can read format models and use TO_CHAR, TO_DATE, and TO_NUMBER with simple formats, as in the earlier chapters. You should also be able to run ALTER SESSION in your client.
Why locale breaks conversions
A format model such as DD-MON-YYYY fixes the layout of a date string. It does not fix the language of MON, and a format model with D or G does not fix which character appears there. Oracle takes those details from NLS (National Language Support) settings.
Two sessions can run the same query against the same data and get different text. A query that works on your laptop can fail in a batch job that runs with a different client locale. The usual fix is to stop depending on session defaults and pass the language and separators with the call.
Where NLS settings come from
Oracle resolves each setting from several layers. The most specific layer wins.
- The
nlsparamargument applies to one function call only. ALTER SESSIONapplies to everything the session runs afterwards.- The client environment is read when a connection starts. For example, the
NLS_LANGenvironment variable is read by OCI-based clients. Other drivers, such as JDBC, usually derive the values from the application's locale. - The database and instance defaults apply when nothing else is set.
You can inspect the values your session uses:
SELECT parameter, value
FROM nls_session_parameters
WHERE parameter IN ('NLS_LANGUAGE', 'NLS_TERRITORY', 'NLS_DATE_FORMAT',
'NLS_DATE_LANGUAGE', 'NLS_NUMERIC_CHARACTERS',
'NLS_CURRENCY')
ORDER BY parameter;NLS_SESSION_PARAMETERS shows the session values. NLS_DATABASE_PARAMETERS shows the database defaults.
The parameters that matter for conversion
| Parameter | Controls | Default comes from |
|---|---|---|
| `NLS_DATE_LANGUAGE` | Language of day and month names (`DAY`, `MONTH`, `MON`, `DY`) | `NLS_LANGUAGE` |
| `NLS_DATE_FORMAT` | Format used for implicit date-to-string conversion | `NLS_TERRITORY` |
| `NLS_NUMERIC_CHARACTERS` | Decimal and group separator characters (two characters, decimal first) | `NLS_TERRITORY` |
| `NLS_CURRENCY` | Local currency symbol, printed by the `L` element | `NLS_TERRITORY` |
| `NLS_ISO_CURRENCY` | Territory whose ISO currency code the `C` element prints | `NLS_TERRITORY` |
NLS_LANGUAGE and NLS_TERRITORY are the parent settings. A language such as GERMAN sets the names of months. A territory such as GERMANY sets separators, currency, and the default date format.
Which format elements depend on NLS
Only some format elements read NLS settings.
| Element | Meaning | Depends on |
|---|---|---|
| `MON`, `MONTH`, `DY`, `DAY` | Month and day names | `NLS_DATE_LANGUAGE` |
| `D` | Decimal separator in a number model | `NLS_NUMERIC_CHARACTERS` |
| `G` | Group separator in a number model | `NLS_NUMERIC_CHARACTERS` |
| `L` | Local currency symbol | `NLS_CURRENCY` |
| `C` | ISO currency code | `NLS_ISO_CURRENCY` |
| `,` and `.` | A literal comma or period | Nothing |
The last row is the source of many bugs. The model 9,999.99 always means a comma and a period, even in a session whose decimal separator is a comma. The model 9G999D99 follows the session. Use G and D when the separators should be adjustable. Use , and . when the string layout is fixed.
The nlsparam argument
Each conversion function takes an optional last argument, nlsparam. It is a string of NAME=value pairs. Which names are accepted depends on the function.
| Function | Accepted names |
|---|---|
| `TO_CHAR` with a date | `NLS_DATE_LANGUAGE` |
| `TO_DATE` | `NLS_DATE_LANGUAGE` |
| `TO_CHAR` with a number | `NLS_NUMERIC_CHARACTERS`, `NLS_CURRENCY`, `NLS_ISO_CURRENCY` |
| `TO_NUMBER` | `NLS_NUMERIC_CHARACTERS`, `NLS_CURRENCY`, `NLS_ISO_CURRENCY` |
You cannot set NLS_DATE_FORMAT through nlsparam. That setting only affects implicit conversion, and an explicit format model replaces it.
An unknown name raises ORA-12702 (invalid NLS parameter string used in SQL function).
Quoting rules
nlsparam is a string literal, so any quotes inside it must be doubled. NLS_NUMERIC_CHARACTERS takes a two-character value, and the value itself is written in quotes:
'NLS_NUMERIC_CHARACTERS='',.'''Read it from the outside in. The outer quotes delimit the SQL string. Inside it, '' stands for one quote character. Oracle therefore sees NLS_NUMERIC_CHARACTERS=',.'. The first character, a comma, is the decimal separator. The second, a period, is the group separator.
Formatting with nlsparam
Dates in another language
SELECT TO_CHAR(DATE '2026-11-28', 'FMDay, DD Month YYYY',
'NLS_DATE_LANGUAGE=GERMAN') AS german_date
FROM dual;The result is Samstag, 28 November 2026. The format model is unchanged. Only the language of Day and Month differs. The capitalization of the output follows the capitalization of the element in the model (Day, DAY, or day).
Numbers with European separators
SELECT TO_CHAR(1234567.891, 'FM9G999G999D00',
'NLS_NUMERIC_CHARACTERS='',.''') AS eu_number
FROM dual;The result is 1.234.567,89. The model uses G and D, so the nlsparam argument decides which characters appear. The value is rounded to two decimals.
Currency symbols
SELECT TO_CHAR(1234.5, 'FML9,999.00', 'NLS_CURRENCY=''EUR''') AS price
FROM dual;The result is EUR1,234.50. The L element prints whatever NLS_CURRENCY says. Here that is a text code, which avoids character-set problems with symbols such as the euro sign on clients that cannot display them.
Parsing with nlsparam
Month names in another language
SELECT TO_CHAR(
TO_DATE('28 novembre 2026', 'DD MONTH YYYY',
'NLS_DATE_LANGUAGE=FRENCH'),
'YYYY-MM-DD') AS iso_date
FROM dual;The result is 2026-11-28. Parsing month names is case-insensitive. The result of TO_DATE is a DATE value. The outer TO_CHAR with an explicit model keeps the display independent of the session format.
Run the same TO_DATE call with an English session and no nlsparam, and it fails with ORA-01843 (not a valid month). The text novembre is not an English month name.
Numbers with a decimal comma
SELECT TO_NUMBER('1.234,56', '9G999D99',
'NLS_NUMERIC_CHARACTERS='',.''') AS eu_style,
TO_NUMBER('1,234.56', '9,999.99') AS us_style
FROM dual;Both columns return 1234.56. The first call needs nlsparam because G and D are session-dependent. The second does not, because , and . in the model are literal.
Mixing the two styles fails. TO_NUMBER('1.234,56', '9,999.99') raises ORA-01722 (invalid number), because the string has a period where the model requires a comma.
Implicit conversion and session settings
Without a format model, Oracle uses the session settings. This is where the risk from the first chapter becomes concrete.
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ',.';
SELECT 'Price: ' || 1234.56 AS txt FROM dual;The result is Price: 1234,56. Switch the session back and you get Price: 1234.56. The same query yields different text, and any code that parses that text later will fail on one of the two.
The reverse direction fails loudly:
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ',.';
SELECT TO_NUMBER('1234.56') AS n FROM dual;This raises ORA-01722. The session decimal separator is now a comma, and a period without a format model is not a valid group separator. Restore your session with ALTER SESSION SET NLS_NUMERIC_CHARACTERS = '.,'; when you finish experimenting.
nlsparam or ALTER SESSION
Both approaches work. They differ in scope and risk.
| Concern | `nlsparam` | `ALTER SESSION` |
|---|---|---|
| Scope | One function call | Everything after the statement |
| Side effects on other code | None | Affects later statements in the session |
| Connection pools | Safe | Setting may leak to the next borrower |
| Verbosity | One extra argument per call | One statement for many calls |
| Covers `NLS_DATE_FORMAT` | No | Yes |
Common errors in this area
- ORA-01843, not a valid month. The month name does not match
NLS_DATE_LANGUAGE. Pass the language innlsparam. - ORA-01722, invalid number. The separators in the string do not match the model or the session. Check whether the model uses
GandDor,and.. - ORA-12702, invalid NLS parameter string. The parameter name is not allowed for that function, or the quoting is wrong. For example,
NLS_DATE_FORMATis rejected. - Abbreviations that differ by language. The abbreviation produced by
MONcan differ between languages and between Oracle versions. For stored or exchanged data, prefer numeric months (MM).
Exercise
A report job runs in a session whose NLSNUMERICCHARACTERS is ',.'. It must read the string '8,750.25' as the number 8750.25. Write a TONUMBER call that works in any session, and say why TONUMBER('8,750.25') alone fails there.
Show answer
Use literal comma and period elements in the model: TONUMBER('8,750.25', '9,999.99'). These elements do not depend on the session, so the result is 8750.25 everywhere. An equivalent form is TONUMBER('8,750.25', '9G999D99', 'NLSNUMERICCHARACTERS=''.,'''). Without a model, Oracle uses the session decimal separator, which is a comma there. The string then has a decimal comma followed by 750.25, which is not a valid number, so ORA-01722 is raised.
Exercise
Write a query that returns the date 2026-12-25 as text in Spanish, in the form 'Viernes, 25 de Diciembre de 2026', without changing any session setting. Which argument selects the language, and what happens if you pass NLSDATEFORMAT there instead?
Show answer
SELECT TOCHAR(DATE '2026-12-25', 'FMDay, DD "de" Month "de" YYYY', 'NLSDATELANGUAGE=SPANISH') AS txt FROM dual; The third argument, nlsparam, selects the language through NLSDATELANGUAGE. The words "de" are quoted so they are copied as literal text. Passing NLSDATE_FORMAT in nlsparam is not allowed for this function and raises ORA-12702. The explicit format model already replaces that setting.