Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

RPAD Function

Description

The RPAD function pads the right side of a string with a specific set of characters.

Syntax

RPAD( char1, n, [, char2 ] ) 

 

char1:

character string

string valued column

NULL

 

n:

integer

NULL

 

char2:

character string

NULL

  • char1: Specifies the string to pad characters to. If n is smaller than the length of char1, padding is not performed, and char1 is truncated to length n and then returned. A single character is processed as 2 or 3 bytes in multi-byte character set environment. If char1 is truncated up to the first byte representing a character according to a value of n, the last byte is removed and an empty character (1 byte) is added to the left because the last character cannot be represented normally. If the value is NULL, NULL is specified.
  • n: Specifies the total length of char1 in bytes. Note that the number and the length of the character strings may be different in multi-byte character set environment. If the value is NULL, NULL is specified.
  • char2: Specifies the string to pad to the right until the length of char1 reaches n. If it is not specified, empty characters (' ') are used as a default. If the value is NULL, NULL is returned.
Example

--character set is euc-kr for Korean characters

 

--it returns only 3 characters if not enough length is specified

SELECT RPAD ('CUBRID', 3, '?');

 rpad('CUBRID', 3, '?')

======================

  'CUB'

 

--on multi-byte charset, it returns the first character only with a right-padded space

SELECT RPAD ('큐브리드', 3, '?');

 rpad('큐브리드', 3, '?')

======================

  '큐 '

 

--padding spaces on the right till char_length is 10

SELECT RPAD ('CUBRID', 10);

 rpad('CUBRID', 10)

======================

  'CUBRID    '

 

--padding specific characters on the right till char_length is 10

SELECT RPAD ('CUBRID', 10, '?');

 rpad('CUBRID', 10, '?')

======================

  'CUBRID????'

 

--padding specific characters on the right till char_length is 10

SELECT RPAD ('큐브리드', 10, '?');

 rpad('큐브리드', 10, '?')

======================

  '큐브리드??'

 

--padding 4 characters on the right

SELECT RPAD ('큐브리드', LENGTH('큐브리드')+4, '?');

 rpad('',  char_length('')+4, '?')

======================

  '큐브리드????'