What MySQL returns, if the length of the original string is greater than the length specified as an argument in LPAD() or RPAD() functions?
In this case, MySQL will not pad anything and truncate the characters from the original string up to the value of length provided as the argument in LPAD() or RPAD() functions.
Example
mysql> Select LPAD('ABCD',3,'*');
+--------------------+
| LPAD('ABCD',3,'*') |
+--------------------+
| ABC |
+--------------------+
1 row in set (0.00 sec)
mysql> Select RPAD('ABCD',3,'*');
+--------------------+
| RPAD('ABCD',3,'*') |
+--------------------+
| ABC |
+--------------------+
1 row in set (0.00 sec)
We can observe from the above example that both the functions do not pad ‘*’ and truncate the original string up to the length specified i.e. 3 as the argument.
Related Articles
- What happens if the length of the original string is greater than the length of the string returned after padding in LPAD() or RPAD() functions?
- What MySQL returns if we provide an empty string for padding with other string in LPAD() or RPAD() functions?
- How can we use MySQL LPAD() and RPAD() functions in the same query for padding the string to both sides, left and right, of the original string?
- What MySQL ELT() function returns if the index number, provided as an argument, is higher than the number of strings?
- How can we use LPAD() or RPAD() functions with the values in the column of a MySQL table?
- What MySQL returns if the search string is not in the list of strings provided as argument in FIELD() function?
- What MySQL returns if the argument of QUOTE() function is NULL?
- What MySQL returns if the first argument of INTERVAL() function is NULL?
- What MySQL returns on passing an invalid string as an argument to STR_TO_DATE() function?
- What MySQL returns if we provide value larger than 255 as argument to MySQL CHAR() function?
- When MySQL SUBSTRING_INDEX() function returns the same string, provided in the argument, as output?
- The length of the shadow of an electric pole in the evening is ____ a) Greater than the length of the electric pole b) Smaller than the length of the electric pole c) Same as the length of the electric pole d) Double the length of the electric pole
- What MySQL returns if the list of strings, provided as argument in FIELD() function, are NULL?
- What MySQL returns if specified format string is not as per accordance with the date string passed as arguments to STR_TO_DATE() function?
- What MySQL TRIM() function returns if 1st argument(i.e. BOTH, LEADING, TRAILING) is not specified?
Kickstart Your Career
Get certified by completing the course
Get Started