This topic describes how to use the string function RPAD in Realtime Compute.

Syntax

VARCHAR RPAD(VARCHAR str, INT len, VARCHAR pad) 

Input parameters

Parameter Data type Description
str VARCHAR The source string.
len INT The length of the new string after padding.
pad VARCHAR The string to be repeatedly padded to the source string.

Description

Right-pads the source string with another string several times until the new string reaches the length specified by len.
  • If any input parameter is set to null, null is returned.
  • If len is negative, null is returned.
  • If pad is an empty string and the value of len is less than or equal to the length of str, str is trimmed to the specified length and the result after trimming is returned.
  • If the value of len is greater than the length of str, null is returned.

Example

  • Test data
    str (VARCHAR) len (INT) pad (VARCHAR)
    null -2 null
    HelloWorld 15 John
    John 2 C
    C 4 HelloWorld
    null 2 C
    c 2 null
    asd 2 null
    null 2 s
    asd 4 null
    null 0 null
  • Test statements
    SELECT  RPAD(str, len, pad) as result
    FROM T1;           
  • Test results
    result (VARCHAR)
    null
    HelloWorldJohnJ
    Jo
    CHel
    null
    null
    as
    ss
    null
    null