From 2d5c2bbac8787be57fa3a69b95703d4eb6c272a2 Mon Sep 17 00:00:00 2001 From: Aolin Date: Wed, 3 Apr 2024 15:48:18 +0800 Subject: [PATCH] Add LPAD() example (#16984) --- 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 6a6c51e9abf7..f6129b24a8d0 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -1139,7 +1139,43 @@ SELECT LOWER(-012); ### [`LPAD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lpad) -返回字符串参数,左侧添加指定字符串 +`LPAD(str, len, padstr)` 函数返回字符串参数,左侧填充指定字符串 `padstr`,直到字符串长度达到 `len` 个字符。 + +- 如果 `len` 小于字符串 `str` 的长度,函数将字符串 `str` 截断到长度 `len`。 +- 如果 `len` 为负数,函数返回 `NULL`。 +- 如果任一参数为 `NULL`,该函数返回 `NULL`。 + +示例: + +```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)