TRIM
将 BTRIM、LTRIM 和 RTRIM 函数合并为单个函数。
行为类型
不可变语法
TRIM ( [ [ LEADING | TRAILING | BOTH ] characters FROM ] expression )
参数
LEADING
- 从字符串左侧移除指定字符
TRAILING
- 从字符串右侧移除指定字符
BOTH
- 从字符串两侧移除指定字符(默认)
characters
- (CHAR 或 VARCHAR)指定要从 expression 中移除的字符。默认值是空格字符。
expression
- (CHAR 或 VARCHAR)是要修剪的字符串
示例
=> SELECT '-' || TRIM(LEADING 'x' FROM 'xxdatabasexx') || '-';
?column?
--------------
-databasexx-
(1 row)
=> SELECT '-' || TRIM(TRAILING 'x' FROM 'xxdatabasexx') || '-';
?column?
--------------
-xxdatabase-
(1 row)
=> SELECT '-' || TRIM(BOTH 'x' FROM 'xxdatabasexx') || '-';
?column?
------------
-database-
(1 row)
=> SELECT '-' || TRIM('x' FROM 'xxdatabasexx') || '-';
?column?
------------
-database-
(1 row)
=> SELECT '-' || TRIM(LEADING FROM ' database ') || '-';
?column?
--------------
-database -
(1 row)
=> SELECT '-' || TRIM(' database ') || '-'; ?column?
------------
-database-
(1 row)