Skip to content

STR

  • number: This is the numerical value that we want to convert into a string. The number parameter must be a valid numeric or decimal value in MySQL.
  • length: This is the total length of the string that will be returned. It includes the decimal point, all digits, signs, etc. If the string is shorter, it’s right-padded with spaces. If it’s longer, it’s truncated to the specified length.
  • decimals: This parameter specifies the number of decimal places to be included in the output. This is counted as part of the total length of the string.
SELECT STR(`5`, `John Doe`);
'5John Doe'

In this example, STR converts the number 5 into a string and then concatenates it with the string John Doe. The result is a single string 5John Doe.