lpad
Returns a string of a specified length. When the length of the given string str is less than the specified length len, the string is padded on the left with the specified character pad. When the length of the given string str is greater than the specified length len, the string is truncated from the left to len characters.
Syntax
lpad(string <str>, int <len>[, string <pad>])
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| str | Yes | STRING | The string to be padded. |
| len | Yes | INT | The length of the result string. |
| pad | No | STRING | The string used for padding. When not specified, the default is a space. |
Return Values
Returns a value of type STRING.
- If len is less than the number of characters in str, the string is truncated from the left to len characters.
- If len is 0, an empty string is returned.
- If there are no input parameters or any input parameter is NULL, NULL is returned.
Example Code
Pad the string abcdefgh on the left with the string ZZ to a length of 10. Return ZZabcdefgh.
select lpad('abcdefgh', 10, 'ZZ'); Pad the string abcdefgh on the left with the string ZZ to a length of 5. Return abcde.
select lpad('abcdefgh', 5, 'ZZ'); length is 0. Return an empty string.
select lpad('abcdefgh', 0, 'ZZ'); Any input parameter is NULL. Return NULL.
select lpad(null, 0, 'ZZ');
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot