> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# initcap

> 将字符串中每个单词的首字母转换为大写，其余字符转换为小写。

将字符串中每个单词的首字母转换为大写，其余字符转换为小写。

此函数适用于标准化文本数据，例如需要统一标题大小写（Title Casing）的姓名、地址或头衔。

## 语法

```SQL theme={null}
initcap(str)
```

## 参数说明

* `str`: 需要格式化的字符串表达式。可以是 VARCHAR 列、字面量字符串或其他字符串函数的结果。

## 返回值

返回格式化后的字符串，类型为 VARCHAR。

> * 如果参数为 NULL，则返回 NULL。
> * 单词由空白字符或非字母数字字符（例如标点符号、符号、数字）分隔。
> * 分隔符后的第一个字符大写；其他所有字母小写。

## 示例

示例 1：格式化基本字符串（全小写或全大写）。

```Plaintext theme={null}
mysql> SELECT initcap('hello world');
+------------------------+
| initcap('hello world') |
+------------------------+
| Hello World            |
+------------------------+
```

```
mysql> SELECT initcap('HELLO WORLD');
+------------------------+
| initcap('HELLO WORLD') |
+------------------------+
| Hello World            |
+------------------------+
```

示例 2：格式化混合大小写字符串。

```Plaintext theme={null}
mysql> SELECT initcap('sTaRroCks dAtAbAsE');
+-------------------------------+
| initcap('sTaRroCks dAtAbAsE') |
+-------------------------------+
| Starrocks Database            |
+-------------------------------+
```

示例 3：处理分隔符（数字、符号和标点）。

```Plaintext theme={null}
mysql> SELECT initcap('1st place, in-the-world!');
+-------------------------------------+
| initcap('1st place, in-the-world!') |
+-------------------------------------+
| 1st Place, In-The-World!            |
+-------------------------------------+
```

## 使用说明

**单词边界：** 函数根据任何非字母或数字的字符来识别“单词”的开头。例如，在 `'abc-def'` 中，连字符 - 是分隔符，因此 d 变为 D。

**数字处理：** 数字如果出现在开头，被视为单词字符，但不会改变大小写。但是，数字后面的符号将重置单词边界（例如，1st -> 1st，因为 1 开始单词，但 1-st -> 1-St，因为 - 是分隔符）。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.