반응형

Syntax:

lpad(string,length[,fill_text])

Parameters:

NameDescriptionReturn Type
stringA string, which will be filled up by another string.text
lengthThe length of the string, which will be after filled up by substring..integer
fill_textThe substring which will be fill up the sting to length.text



Pictorial Presentation of PostgreSQL LPAD() function

Pictorial presentation of PostgreSQL LPAD() function




Code:


SELECT lpad('esource', 10, 'w3r');

Sample Output:

    lpad
------------
 w3resource
(1 row)

Example 2:

In the example below, the main string is 'esource' and its length is 7, the substring is 'w3r' of length 3 and the string have to be a length of 13. So, remaining length is 6, and the substring 'w3r' will repeat two times to fill it up, thus the result is 'w3rw3resource'.

Code:

SELECT lpad('esource', 13, 'w3r');

Sample Output:

    lpad
---------------
 w3rw3resource
(1 row)

Example 3:

In the example below, the main string is 'w3resource' and its length is 10, the substring is 'lpad' of length 4 and the string have to be a length of 8. Here, the specified length is smaller than the string, so, instead of lpadding the string will be truncated by two characters from the right side of the string, thus the result is 'w3resour'.

Code:

SELECT lpad('w3resource', 8, 'lpad');

Sample Output:

  lpad
----------
 w3resour
(1 row)



출처 : https://w3resource.com/PostgreSQL/lpad-function.php

반응형

'Postgresql' 카테고리의 다른 글

Postgresql 프로시저 만들기  (0) 2019.01.08
Postgresql 타입별 연산  (0) 2019.01.08
ORACLE Postgresql 변환  (0) 2018.12.27
Postgresql 스키마 권한  (0) 2018.12.27
Postgresql 계층형 쿼리 구현 방법  (0) 2018.12.27

+ Recent posts