TRANSLATE scalar function syntax
The syntax of the TRANSLATE scalar function depends on whether NPS compatibility mode is being used.
- When SQL_COMPAT='NPS', the syntax of the TRANSLATE scalar function is as
described in Syntax of the TRANSLATE scalar function when SQL_COMPAT='NPS'. For
example:
returns:translate('12345', '143', 'ax')
In the stringa2x5
'12345'
:- The character
1
is translated toa
. - The character
4
is translated tox
. - The character
3
does not have a corresponding character in the "to" string, so it is removed.
- The character
- Otherwise, the syntax of the TRANSLATE scalar function is as described in TRANSLATE scalar function. For
example:
returns:translate('12345', 'ax', '143')
In the stringa2 x5
'12345'
:- The character
1
is translated toa
. - The character
4
is translated tox
. - The character
3
does not have a corresponding character in the "to" string, so it is replaced with a padding character. The default padding character is a blank.
- The character
Syntax of the TRANSLATE scalar function when SQL_COMPAT='NPS'
This function converts all the characters in char-string-exp that also occur in from-string-exp to the corresponding characters in to-string-exp. If from-string-exp is longer than to-string-exp, occurrences of the extra characters in from-string-exp are removed from char-string-exp.
- char-string-exp
- The string that is to be converted. The expression must return a value that is a built-in CHAR, VARCHAR, GRAPHIC, VARGRAPHIC, numeric, or datetime data type. If the value is not a CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC data type, it is implicitly cast to VARCHAR before evaluating the function.
- from-string-exp
- A string of characters that, if found in char-string-exp, are to be
converted to the corresponding character in to-string-exp.
The expression must return a value that is a built-in CHAR, VARCHAR, GRAPHIC, VARGRAPHIC, numeric, or datetime data type. If the value is not a CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC data type, it is implicitly cast to VARCHAR before evaluating the function. If from-string-exp contains duplicate characters, the first one found will be used, and the duplicates will be ignored. If to-string-exp is longer than from-string-exp, the surplus characters will be ignored. If to-string-exp is specified, from-string-exp must also be specified.
- to-string-exp
- A string of characters to which certain characters in char-string-exp
arre to be converted.
The expression must return a value that is a built-in CHAR, VARCHAR, GRAPHIC, VARGRAPHIC, numeric, or datetime data type. If the value is not a CHAR, VARCHAR, GRAPHIC, or VARGRAPHIC data type, it is implicitly cast to VARCHAR before evaluating the function. If a value for to-string-exp is not specified, and the data type is not graphic, all characters in char-string-exp will be in monocase; that is, the characters a-z will be converted to the characters A-Z, and other characters will be converted to their uppercase equivalents, if they exist. For example, in code page 850, é maps to É, but ÿ is not mapped, because code page 850 does not include Ÿ. If the code point length of the result character is not the same as the code point length of the source character, the source character is not converted.