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; -----------------