Get the App
SLTechnology News&Howtos  ›  Database  › 

How to understand lpad and rpad functions

Shulou Source: shulou.com Published: 2022-05-31 14:16:07 09月29日 Update

This article will explain in detail how to understand lpad and rpad functions, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

1. Lpad function

The lpad function fills the string on the left with specific characters in the following syntax format: lpad (string,n, [pad_string])

String: characters or parameters

N: the length of the character is the number of strings returned. If this number is shorter than the length of the original string, the lpad function will truncate the string into n characters from left to right.

Pad_string: optional parameter. The string is to be pasted to the left of string. If this parameter is not written, the lpad function will paste a space to the left of string.

Select lpad ('tech', 7) from dual; will return' tech'

Select lpad ('tech', 2) from dual; will return' te'

Select lpad ('tech', 8,' 0') from dual; will return to '0000tech'

Select lpad ('tech on the net', 15,' z') from dual; will return 'tech on the net'

Select lpad ('tech on the net', 16,' z') from dual; will return 'ztech on the net'

SQL > select lpad ('tech', 7) from dual

LPAD ('T)

-

Tech

SQL > select lpad ('tech', 2) from dual

LP

--

Te

SQL > select lpad ('tech', 8,' 0') from dual

LPAD ('TE

-

0000tech

SQL > select lpad ('tech on the net', 15,' z') from dual

LPAD ('TECHONTHE

-

Tech on the net

SQL > select lpad ('tech on the net', 16,' z') from dual

LPAD ('TECHONTHEN

-

Ztech on the net

SQL >

2. Rpad function

The rpad function fills the string on the right with specific characters in the syntax format: rpad (string,n, [pad_string])

String: characters or parameters

N: the length of the character is the number of strings returned. If this number is shorter than the length of the original string, the lpad function will truncate the string into n characters from left to right.

Pad_string: optional parameter, this string is to be pasted to the right of string, if this parameter is not written, the lpad function will paste a space to the right of string.

Select rpad ('tech', 7) from dual; will return' tech'

Select rpad ('tech', 2) from dual; will return' te'

Select rpad ('tech', 8,' 0') from dual; will return 'tech0000'

Select rpad ('tech on the net', 15,' z') from dual; will return 'tech on the net'

Select rpad ('tech on the net', 16,' z') from dual; will return 'tech on the netz'

SQL > select rpad ('tech', 7) from dual

RPAD ('T)

-

Tech

SQL > select rpad ('tech', 2) from dual

RP

--

Te

SQL > select rpad ('tech', 8,' 0') from dual

RPAD ('TE

-

Tech0000

SQL > select rpad ('tech on the net', 15,' z') from dual

RPAD ('TECHONTHE

-

Tech on the net

SQL > select rpad ('tech on the net', 16,' z') from dual

RPAD ('TECHONTHEN

-

Tech on the netz

On how to understand the lpad and rpad functions to share here, I hope the above can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Characters functions strings parameters quantity length right content articles more formatting knowledge spaces articles grammar good quality reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Apple OPPO Reno macOS Linux