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 until the string length reaches the specified value.

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. If the value is NULL, NULL is specified.
  • n: Specifies the total length of char1. 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.

Note In versions lower than CUBRID 9.0, a single character is processed as 2 or 3 bytes in a multi-byte character set environment. If n is truncated up to the first byte representing a character according to a value of char1, the last byte is removed and a space character (1 byte) is added to the right because the last character cannot be represented normally. When the value is NULL, NULL is returned as its result.

Example

--character set is UTF-8 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, '?')

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

  '큐브리드????'