I have a requirement that when a string length is less than 10, I need to append as many stars(*) at the end till length equals to 10.
ipString = "Stack"
opString = "Stack*****"
SET @str := 'Stack '; SELECT IF(LENGTH(@str) < 10, RPAD(@str,10,'*') ,@str)
WORKING DEMO If the length of the string is less than 10
WORKING DEMO If the length of the string is greater than or equal to 10
MySQL RPAD() function pads strings from right. The actual string which is to be padded, length of the string returned after padding and string which is used for padding - all these are passed as arguments.
RPAD(str, len, padstr)
Name Description str The actual string which is to be padded. len Length of the string returned after padding. padstr String which will be used for padding.