How to use Lpad and RPAD functions in Oracle (plus personal Summary)

Source: Internet
Author: User

See two of the functions that have not been seen in SQL today, summarize;

Function parameters:lpad (string1, padded_length, [pad_string])

which

String1: source string

Padded_length: The length of the string returned by the final result, and if the length of the final returned string is smaller than the source string, then this function actually intercepts the source strings, exactly as substr (String,number1,number2) does. If the padded_length is longer than the length of the source string, it is populated with pad_string, ensuring that the length of the final string returned is padded_length;

Pad_string: The character used for padding, can not be filled, default is null character

Instance:

Select lpad ('123456',2 from dual- Results A
Select lpad ('123456',7,'0'   from dual-- result is 0123456
--note that in the left padding Lpad L is left, meaning
 select  rpad ( " 123456   ", 2 , "  0   ") from   dual  --  
Select rpad ('123456',7,'0' from Dual -- result is 1234560
--rpad padding on the right, R to right

Summarize:

As you can see, when the length of the string1 source string is less than padded_length, the function of Lpad and Rpad is the same, which is equivalent to the substr intercept string, when Padded_length is greater than the length of the string1 source string, Lpad to fill the left side of the source string with the specified character or space, rpad to the right of the source string to fill the specified character or space;

How to use Lpad and RPAD functions in Oracle (plus personal Summary)

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.