Use of the padding function lpad/rpad in oracle, lpadrpad

Source: Internet
Author: User

Use of the padding function lpad/rpad in oracle, lpadrpad

Lpad 1. Syntax Lpad (string, pad_length, [pad_str])
2. Explanation
This function indicates filling the specified character to the specified length from the left side of the string. The space of the string is also included in the length.
String: the length of the string to be filled. If the value is smaller than the length of the original string, the return value is the string of this length starting from the left side of the string. Pad_str: string to be filled. An optional function. If there is no value, fill the left side with a space.
Example 1: select lpad ('abc', '5', '@') from dual; ------------------ @ abc Example 2: select lpad ('abcdef', '5 ', '@') from dual; --------------------- abcde Example 3: select lpad ('AB cdefg', '5',' @ ') from dual; ----------------------- AB cd Example 4: select lpad ('abc', '5') from dual; ------------- abc

Rpad:
1. Syntax: Rpad (string, pad_length, [pad_str])
2. Explanation
This function indicates filling the specified character to the specified length from the right of the string. The space of the string is also included in the length.
String: the length of the string to be filled. If the value is smaller than the length of the original string, the return value is the string of this length starting from the left side of the string. Pad_str: string to be filled. An optional function. If there is no value, fill the right side with a space.
Example 1: select rpad ('abc', '5', '#') from dual; ----------------- abc ##
Example 2: select rpad ('AB C', '5',' # ') from dual; ----------------- AB c #
Example 3: select rpad ('abc', '2', '#') from dual; ----------------- AB
Example 4: select rpad ('abc', '2', '#') from dual; -----------------






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.