>>-RIGHT--(--string-expression--,--length--+--------------------+--)->< '-,--+-CODEUNITS16-+-' +-CODEUNITS32-+ '-OCTETS------'
The schema is SYSIBM. The SYSFUN version of the RIGHT function continues to be available.
The RIGHT function returns the rightmost string of string-expression of length length, expressed in the specified string unit. If string-expression is a character string, the result is a character string. If string-expression is a graphic string, the result is a graphic string
CODEUNITS16 specifies that length is expressed in 16-bit UTF-16 code units. CODEUNITS32 specifies that length is expressed in 32-bit UTF-32 code units. OCTETS specifies that length is expressed in bytes.
If the string unit is specified as CODEUNITS16 or CODEUNITS32, and string-expression is a binary string or bit data, an error is returned (SQLSTATE 428GC). If the string unit is specified as OCTETS and string-expression is a graphic string, length must be an even number; otherwise, an error is returned (SQLSTATE 428GC). If a string unit is not explicitly specified, the data type of the result determines the unit that is used. If the result is graphic data, length is expressed in two-byte units; otherwise, it is expressed in bytes. For more information about CODEUNITS16, CODEUNITS32, and OCTETS, see "String units in built-in functions" in "Character strings".
The string-expression is padded on the right with the necessary number of padding characters so that the specified substring of string-expression always exists. The character used for padding is the same character that is used to pad the string in contexts where padding would occur. For more information on padding, see "String assignments" in "Assignments and comparisons".
If any argument can be null, the result can be null; if any argument is null, the result is the null value.
Examples:
SELECT RIGHT(ALPHA,3)
FROM SYSIBM.SYSDUMMY1
returns 'DEF', which
are the three rightmost characters in ALPHA. SELECT RIGHT(NAME,LASTNAME_LEN)
FROM SYSIBM.SYSDUMMY1
returns the value 'AUSTIN'. SELECT RIGHT('ABCABC',0)
FROM SYSIBM.SYSDUMMY1
SELECT RIGHT(FIRSTNME, 10)
FROM EMPLOYEE
WHERE LASTNAME = 'BROWN'
returns a VARCHAR(12)
string that has the value 'DAVID' followed by five blank characters. Function... Returns...
RIGHT(FIRSTNAME,5,CODEUNITS32) 'ürgen' -- x'C3BC7267656E'
RIGHT(FIRSTNAME,5,CODEUNITS16) 'ürgen' -- x'C3BC7267656E'
RIGHT(FIRSTNAME,5,OCTETS) 'rgen' -- x'207267656E', a truncated string
'&' | 'N' | '~' | 'A' | 'B' | |
---|---|---|---|---|---|
UTF-8 | X'F09D849E' | X'4E' | X'CC83' | X'41' | X'42' |
UTF-16BE | X'D834DD1E' | X'004E' | X'0303' | X'0041' | X'0042' |
SELECT RIGHT(UTF8_VAR, 2, CODEUNITS16),
RIGHT(UTF8_VAR, 2, CODEUNITS32),
RIGHT(UTF8_VAR, 2, OCTETS)
FROM SYSIBM.SYSDUMMY1
returns the values 'AB',
'AB', and 'AB', respectively. SELECT RIGHT(UTF8_VAR, 5, CODEUNITS16),
RIGHT(UTF8_VAR, 5, CODEUNITS32),
RIGHT(UTF8_VAR, 5, OCTETS)
FROM SYSIBM.SYSDUMMY1
returns the values '?N~AB',
'&N~AB', and 'N~AB', respectively, where '?' is X'EDB49E'. SELECT RIGHT(UTF8_VAR, 10, CODEUNITS16),
RIGHT(UTF8_VAR, 10, CODEUNITS32),
RIGHT(UTF8_VAR, 10, OCTETS)
FROM SYSIBM.SYSDUMMY1
returns the values '&N~ABbbbb',
'&N~ABbbbbb', and '&N~ABb', respectively, where
'b' represents the blank character. SELECT RIGHT(UTF16_VAR, 2, CODEUNITS16),
RIGHT(UTF16_VAR, 2, CODEUNITS32),
RIGHT(UTF16_VAR, 2, OCTETS))
FROM SYSIBM.SYSDUMMY1
returns the values 'AB',
'AB', and 'B', respectively. SELECT RIGHT(UTF16_VAR, 5, CODEUNITS16),
RIGHT(UTF16_VAR, 5, CODEUNITS32),
RIGHT(UTF16_VAR, 6, OCTETS)
FROM SYSIBM.SYSDUMMY1
returns the values '?N~AB',
'&N~AB', and '~AB', respectively, where '?' is the standalone
low surrogate X'DD1E'. SELECT RIGHT(UTF16_VAR, 10, CODEUNITS16),
RIGHT(UTF16_VAR, 10, CODEUNITS32),
RIGHT(UTF16_VAR, 10, OCTETS)
FROM SYSIBM.SYSDUMMY1
returns the values '&N~ABbbbb',
'&N~ABbbbbb', and '?N~AB', respectively, where 'b'
represents the blank character and '?' is X'DD1E'.