<<<<<<< HEAD rpad | H2 | SQLDoc
Skip to main content

rpad

1. RPAD Function

======= rpad | H2 Function | SQLDoc

rpad

1. RPAD Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The 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 to len, 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 str argument is required, but the len and padChar arguments are optional. If not provided, len defaults to 0 and padChar defaults to a space character.
  • If the len argument is negative, the RPAD function will return an empty string.
  • If the padChar argument 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 len after 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
  • lpad - Pad a string from the left side.