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

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, '?')

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

  '큐브리드????'