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 | 



LPAD Function

Description

The LPAD function pads the left side of a string with a specific set of characters.

Syntax

LPAD( 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 a space character (1 byte) is added to the left because the last character cannot be represented normally. If the value is NULL, NULL is returned.
  • 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 returned.
  • char2 : Specifies the string to pad to the left 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 LPAD ('CUBRID', 3, '?');

  lpad('CUBRID', 3, '?')

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

  'CUB'

 

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

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

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

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

  ' 큐'

 

--padding spaces on the left till char_length is 10

SELECT LPAD ('CUBRID', 10);

 lpad('CUBRID', 10)

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

  '    CUBRID'

 

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

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

 lpad('CUBRID', 10, '?')

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

  '????CUBRID'

 

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

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

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

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

  '??큐브리드'

 

--padding 4 characters on the left

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

 lpad('큐브리드',  char_length('큐브리드')+4, '?')

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

  '????큐브리드'