mysql trim()函数用于从字符串中删除特定的后缀、前缀或两者。trim()函数的工作原理可以通过其语法来理解 −
语法trim([{both | leading | trailing} [str_to_remove] from] string)
这里,
参数 both 表示要从字符串中删除左右两侧的前缀。leading 参数表示仅要删除的前导前缀。trailing 参数表示仅删除尾随前缀。str_to_remove 是参数,表示我们要从字符串中删除的字符串。str_to_remove 是参数,表示我们要从字符串中删除的字符串。 >字符串参数表示必须删除前缀的字符串。示例在这里,
both参数表示要从字符串中同时删除左侧和右侧的前缀。leading参数表示只删除前缀。trailing参数表示只删除后缀。str_to_remove是要从字符串中删除的字符串参数。string参数表示要从中删除前缀的字符串。示例mysql> select trim(both '0' from '0100');+----------------------------+| trim(both '0' from '0100') |+----------------------------+| 1 |+----------------------------+1 row in set (0.00 sec)mysql> select trim(both '**' from '**tutorialspoint.com**');+------------------------------------------------+| trim(both '**' from '**tutorialspoint.com**') |+------------------------------------------------+| tutorialspoint.com |+------------------------------------------------+1 row in set (0.00 sec)mysql> select trim(trailing '**' from '**tutorialspoint.com**');+----------------------------------------------------+| trim(trailing '**' from '**tutorialspoint.com**') |+----------------------------------------------------+| **tutorialspoint.com |+----------------------------------------------------+1 row in set (0.00 sec)mysql> select trim(leading '**' from '**tutorialspoint.com**');+---------------------------------------------------+| trim(leading '**' from '**tutorialspoint.com**') |+---------------------------------------------------+| tutorialspoint.com** |+---------------------------------------------------+1 row in set (0.00 sec)
以上就是mysql trim() 函数的用途是什么?的详细内容。
