Skip to content

LPAD

  • str: The string to be padded. The function will add characters to the left side of this string.
  • len: The length of the resulting string after padding. If this value is less than the length of the original string, the function will trim the characters from the left.
  • padstr: The string to use for padding. The function will append this string to the left of the original string until it reaches the length specified by len. If padstr is more than one character long or len is greater than the length of str, the function will repeat padstr as many times as required but will cut it short to meet the specified length.
SELECT LPAD('SQL', 6, 'AB');
'ABABSQL'

In the above SQL statement, LPAD function is used to pad the left side of a string with a specific set of characters. The syntax is LPAD(str, len, padstr). Here, ‘SQL’ is the original string, 6 is the length for the resulting string, and ‘AB’ are the padding characters. Consequently, ‘ABABSQL’ is produced.