SQL/MX 3.1 Reference Manual (H06.23+, J06.12+)

SQL/MX Functions and Expressions
HP NonStop SQL/MX Release 3.1 Reference Manual663850-001
9-95
Examples of LPAD
The following LPAD function returns the original string 'go fly a kite' because
the count is equal to the length of the string:
LPAD('go fly a kite', 13, 'z')
The following LPAD function returns a string of 10 characters ' Robert' by left
padding the string 'Robert' with four spaces:
LPAD('Robert',10)
The following LPAD function returns a string of eight characters '0000kite' by left
padding the string 'kite' with four pad-characters '0':
LPAD('kite', 8, '0')
The following LPAD function returns 'John,John, go fly a kite':
LPAD('go fly a kite', 23, 'John,')
The function left pads the string 'go fly a kite' with the string 'John,' such that
the length of the result string is 23 characters.
The following LPAD function returns 'John,Jogo fly a kite':
LPAD('go fly a kite', 20, 'John,')
The function left pads the string 'go fly a kite' with the string 'John,' such that
the length of result string is 20 characters.
The default behavior of the LPAD function and the corresponding examples are
described below.
The count specifies the number of characters to be replaced. The count must be
less than or equal to the length of the character-expr. If count is smaller than or
equal to the length of the character-expr, the leftmost count characters of the
character-expr are replaced with the padding characters or string. If count is
greater than the length of the character-expr, an error is returned.
The following LPAD function replaces two leftmost characters in the string 'kite'
with spaces and returns ' te':
LPAD('kite', 2)
The following LPAD function replaces six leftmost characters in the string 'Robert
John Smith' with spaces and returns ' John Smith':
LPAD('Robert John Smith', 6);
The following LPAD function replaces two leftmost characters 'go' with the string
'John,' twice and returns 'John,John, fly a kite':
LPAD('go fly a kite', 2, 'John,')
The following LPAD function replaces 13 leftmost characters in the string 'go fly
a kite' with character 'z' and returns 'zzzzzzzzzzzzz'
LPAD('go fly a kite', 13, 'z')