Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand lpad and rpad functions

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report