rpad
1. RPAD Function
=======rpad
1. RPAD Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe RPAD function in H2 database is used to pad a string value with a specified character to a specified length.
2. Syntax
The syntax for the RPAD function in H2 database is as follows:
RPAD(str, len, padChar)
Arguments
str: The input string that needs to be padded.len: The desired length of the resulting string after padding. If the length of the input string is already greater than or equal tolen, no padding will be applied.padChar: The character used for padding the string. It should be a single character or a string of length 1.
Return
- The RPAD function returns the input string padded with the specified character to the specified length.
3. Notes
- The
strargument is required, but thelenandpadChararguments are optional. If not provided,lendefaults to 0 andpadChardefaults to a space character. - If the
lenargument is negative, the RPAD function will return an empty string. - If the
padCharargument is an empty string, the RPAD function will return the input string as is. - The RPAD function will truncate the input string if its length exceeds the specified
lenafter padding.
4. Examples
Here are a few examples demonstrating the usage of the RPAD function in H2 database:
Example 1 - Padding a string with spaces to a specific length:
SELECT RPAD('Hello', 10) AS padded_string;
Output:
padded_string
-------------
Hello
Example 2 - Padding a string with a custom character:
SELECT RPAD('Hello', 10, '*') AS padded_string;
Output:
padded_string
-------------
Hello*****
Example 3 - Truncating the input string if it exceeds the specified length:
SELECT RPAD('Hello World!', 5) AS padded_string;
Output:
padded_string
-------------
Hello
5. Related Functions
- lpad - Pad a string from the left side.