[TOC]
<br>
<br>
| 函数 | 用途 |
| --- | --- |
| concat | 拼接字符串 |
| UPPER | 将字符全部大写 |
| lower | 将字符全部小写 |
| length | 获取参数值的字节数 |
| substr | 截取字符按照索引 |
| instr | 返回起始索引的下标 |
<br>
<br>
>[success] ## 一:字符函数
<br>
<br>
>[info]### **1:length**:就是获取一个字符的长度
```sql
select LENGTH('臧三');
```
结果:`6`一个字母占一个字节,一个汉字占3个字节
```sql
select LENGTH('zhangsan');
```
结果:`8`
<br>
<br>
>[info]### **2:concat:拼接字符**
```sql
SELECT
CONCAT( first_name, "_", phone_number )
FROM
gin_employees;
```
结果:
:-: ![](https://img.kancloud.cn/f3/e6/f3e6b74278caaaae079129cd965f3a29_337x272.png)
<br>
<br>
>[info]### **3:upper:将字符全部转成大写**
```sql
select UPPER('jack')
```
**结果**:JACK
<br>
<br>
>[info]### **4:lower:将字符全部转成小写**
```sql
select lower('JACK')
```
**结果**: jack
<br>
<br>
**案例演示:**
将姓变成大写,名变成小写,然后拼接
```sql
SELECT
CONCAT(
UPPER( first_name ),
LOWER( last_name )) AS 姓名
FROM
gin_employees;
```
<br>
<br>
>[info]### **5:substr:截取字符按照索引**
**注意**:在sql中索引是从0开始的
```sql
SELECT
SUBSTR( '张三丰喜欢上了郭襄', 8 ) out_put;
```
**结果**:郭襄
<br>
**案例演示**
姓名中首字母大写,其他字符小写然后用_拼接,显示出来
```sql
SELECT
CONCAT(
UPPER(
substr( first_name,1,1)),
'_',
LOWER(SUBSTR(first_name,2))) out_put
FROM
gin_employees;
```
<br>
<br>
<br>
>[info]### **5:instr:返回子字符串第一次出现的索引**
```sql
SELECT
INSTR( "董永爱上了七仙女", "七仙女" ) AS out_put;
```
**结果**:6
<br>
<br>