The RIGHT function returns the rightmost integer characters of expression.
If expression is a character string, the result is a character string. If expression is a graphic string, the result is a graphic string. If expression is a binary string, the result is a binary string.
A substring of expression is zero or more contiguous characters of expression. If expression is a character string or graphic string, a single character is either an SBCS, DBCS, or multiple-byte character. If expression is a binary string, the result is the number of bytes in the argument.
The result of the function is a varying-length string with a length attribute that is the same as the length attribute of expression and a data type that depends on the data type of expression:
| Data type of expression | Data type of the Result |
|---|---|
| CHAR or VARCHAR | VARCHAR |
| CLOB | CLOB |
| GRAPHIC or VARGRAPHIC | VARGRAPHIC |
| DBCLOB | DBCLOB |
| BINARY or VARBINARY | VARBINARY |
| BLOB | BLOB |
The actual length of the result is integer.
If any argument can be null, the result can be null; if any argument is null, the result is the null value.
The CCSID of the result is the same as that of expression.
SELECT RIGHT( :ALPHA, 3) FROM SYSIBM.SYSDUMMY1Returns the value 'DEF', which are the three rightmost characters in ALPHA.
SELECT RIGHT( 'ABCABC', 0) FROM SYSIBM.SYSDUMMY1
SELECT RIGHT(NAME, 5), SUBSTR(NAME, 3, 5) FROM T1 WHERE NAME = 'Jürgen'Returns the value 'ürgen' for RIGHT and an unprintable string (X'BC7267656E') for SUBSTR(NAME, 3, 5).