oracle rpad () and LPAD () function

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

rpad filling function from the right using the specified character string   

  • string represents: a string filled
  • padded_length represents: the length character string number is returned, if this number is shorter than the length of the string, the string will function RPAD taken from left to right into the n characters;  
  • pad_string is an optional parameter, this string is the string to be pasted to the right

Example:

select rpad('1147076062',3) as 结果 from dual;

 select rpad('1147076062',6,0) as 结果 from dual;

 SELECT RPAD ( ' 1,147,076,062 ' , 12 is , ' QQ ' ) AS results from Dual;

 

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

lpad function from the left filled using the specified character string

  • string1: String filled 
  • padded_length: i.e., the final length of the string returned results; if the final length of the returned string, then the function is actually the source string extraction process is smaller than the source string, the effect substr (string, number1, number2) of exactly, if the length is longer than padded_length source string is padded with pad_string, to ensure that the final length of the string is returned padded_length;
  • pad_string: character used to fill in, can not fill, the default is the null character

Example:

select lpad('1147076062',3) as 结果 from dual;
select lpad('1147076062',6,0) as 结果 from dual;
SELECT LPAD ( ' 1,147,076,062 ' , 12 is , ' QQ ' ) AS results from Dual;

NOTE: It can be seen when less than the length of the source string string1 padded_length, lpad, rpad role is the same, equivalent are taken substr string, string1 when padded_length greater than the length of the source string, the source is LPAD filling the specified character string left or space, rpad filled specified character string or the right side of the source space;

Guess you like

Origin www.cnblogs.com/su-root/p/11682066.html