在Hive中,TRIM函数用于删除字符串的开头和结尾的空格。该函数的语法如下:
```sql
TRIM([BOTH | LEADING | TRAILING] trim_character FROM input_string)
```
- 如果不指定trim_character,则默认删除空格。
- 如果指定BOTH,则删除开头和结尾的指定字符或空格。
- 如果指定LEADING,则删除开头的指定字符或空格。
- 如果指定TRAILING,则删除结尾的指定字符或空格。
示例如下:
```sql
SELECT TRIM(' hello ') AS trimmed_string; -- 输出:'hello'
SELECT TRIM(BOTH 'x' FROM 'xhellox') AS trimmed_string; -- 输出:'hello'
SELECT TRIM(LEADING 'x' FROM 'xxhello') AS trimmed_string; -- 输出:'hello'
SELECT TRIM(TRAILING 'x' FROM 'helloxx') AS trimmed_string; -- 输出:'hello'
```