在SQL中,TRIM函数用于去除字符串的首尾空格或指定字符。其语法如下:
```sql
TRIM([LEADING | TRAILING | BOTH] [characters FROM] string)
```
参数说明:
- LEADING: 去除字符串开头的指定字符
- TRAILING: 去除字符串末尾的指定字符
- BOTH: 同时去除字符串开头和末尾的指定字符
- characters: 要去除的字符,默认为首尾空格
- string: 要去除空格或指定字符的字符串
示例:
```sql
SELECT TRIM(' hello ') AS trimmed_string; -- 结果为 'hello'
SELECT TRIM(LEADING '0' FROM '00012345') AS trimmed_string; -- 结果为 '12345'
SELECT TRIM(BOTH '0' FROM '00012345') AS trimmed_string; -- 结果为 '12345'
SELECT TRIM(TRAILING '0' FROM '12345000') AS trimmed_string; -- 结果为 '12345'
```