All SQL functions whose behavior depends on NLS conventions allow NLS parameters to be specified. These functions are
For example, the following query is only evaluated correctly if the language being for dates is American:
SELECT ENAME FROM EMP WHERE HIREDATE > '1-JAN-91'
Such a query can be made independent of the current date language using:
SELECT ENAME FROM EMP WHERE HIREDATE > TO_DATE('1-JAN-91','DD-MON-YY', 'NLS_DATE_LANGUAGE = AMERICAN')
In this way, language-independent SQL statements can be defined where necessary. For example, such statements may be necessary when string literals appear in SQL statements in views, CHECK constraints, or triggers.
'parameter = value'
The following NLS parameters may be specified:
TO_DATE ('1-JAN-89', 'DD-MON-YY', 'nls_date_language = American') TO_CHAR (hiredate, 'DD/MON/YYYY', 'nls_date_language = French') TO_NUMBER ('13.000,00', '99G999D99', 'nls_numeric_characters = ''.,''') TO_CHAR (sal, '9G999D99L', 'nls_numeric_characters = ''.,'' nls_currency = ''Dfl ''') TO_CHAR (sal, '9G999D99C', 'nls_numeric_characters = '',.'' nls_iso_currency = Japan') NLS_UPPER (ename, 'nls_sort = Austrian') NLSSORT (ename, 'nls_sort = German')
Note: For some languages, various lowercase characters correspond to a sequence of uppercase characters, or vice versa. As a result, the output from NLS_UPPER, NLS_LOWER, and NLS_INITCAP can differ from the length of the input.
If an NLS parameter is specified in TO_CHAR, TO_NUMBER, or TO_DATE, a format mask must also be specified as the second parameter. For example, the following specification is legal:
TO_CHAR (hiredate, 'DD/MON/YY', 'nls_date_language = French')
These are illegal:
TO_CHAR (hiredate, 'nls_date_language = French') TO_CHAR (hiredate, 'nls_date_language = French', 'DD/MON/YY')
This restriction means that a date format must always be specified if an NLS parameter is in a TO_CHAR or TO_DATE function. As a result, NLS_DATE_FORMAT is not a valid NLS parameter for these functions.
For more information on CONVERT, see Oracle7 Server SQL Reference.
The CONVERT function converts the binary representation of a character string in one character set to another. It uses exactly the same technique as described previously for the conversion between database and client character sets. Hence, it uses replacement characters and has the same limitations. The syntax for CONVERT is:
where src_char_set is the source and dest_char_set is the destination character set.
SELECT COL1 FROM TAB1 WHERE COL1 > 'B'
returns both BCD and ÄBC because Ä has a higher numeric value than B. However, in German, an Ä is sorted alphabetically before B. Such conventions are language dependent even when the same character is used. In Swedish, an Ä is sorted after Z. Linguistic comparisons can be made using NLSSORT in the WHERE clause, as follows:
WHERE NLSSORT(col) comparison_operator NLSSORT(comparison_string)
Note that NLSSORT has to be on both sides of the comparison operator. For example:
SELECT COL1 FROM TAB1 WHERE NLSSORT(COL1) > NLSSORT('B')
If a German linguistic sort is being used, this does not return strings beginning with Ä because in the German alphabet Ä comes before B. If a Swedish linguistic sort is being used, such names are returned because in the Swedish alphabet Ä comes after Z.
In other words, the NLSSORT linguistic replacement is only applied once, not twice. The NLSSORT function is generally not needed in an ORDER BY clause when the default sort mechanism is a linguistic sort. However, when the default sort mechanism is BINARY, then a query such as:
SELECT ENAME FROM EMP ORDER BY ENAME
will use a binary sort. A German linguistic sort can be obtained using:
SELECT ENAME FROM EMP ORDER BY NLSSORT(ENAME, 'NLS_SORT = GERMAN')