From d14cb24390b1a4b43e753b64ea8630ce9fd48120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Wed, 3 Apr 2024 09:48:25 +0200 Subject: [PATCH] Add LPAD() example (#16946) --- functions-and-operators/string-functions.md | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index ddf8310916d0f..e2d9d93ae49f9 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1186,7 +1186,43 @@ SELECT LOWER(-012); ### [`LPAD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lpad) -Return the string argument, left-padded with the specified string. +The `LPAD(str, len, padstr)` function returns the string argument, left-padded with the specified string `padstr` to a length of `len` characters. + +- If `len` is less than the length of the string `str`, the function truncates the string `str` to the length of `len`. +- If `len` is a negative number, the function returns `NULL`. +- If any argument is `NULL`, the function returns `NULL`. + +Examples: + +```sql +SELECT LPAD('TiDB',8,'>'); ++--------------------+ +| LPAD('TiDB',8,'>') | ++--------------------+ +| >>>>TiDB | ++--------------------+ +1 row in set (0.00 sec) +``` + +```sql +SELECT LPAD('TiDB',2,'>'); ++--------------------+ +| LPAD('TiDB',2,'>') | ++--------------------+ +| Ti | ++--------------------+ +1 row in set (0.00 sec) +``` + +```sql +SELECT LPAD('TiDB',-2,'>'); ++---------------------+ +| LPAD('TiDB',-2,'>') | ++---------------------+ +| NULL | ++---------------------+ +1 row in set (0.00 sec) +``` ### [`LTRIM()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ltrim)