1. 替换字符串中的某一个子串
postgres=# select replace('you are a man,old man','man','woman'); you are a woman,old woman
postgres=# select translate('you are a man,'woman'); you ore o wom,old wom可以看出,translate把替换后的子串截断成原来的子串的长度。
2. trim相关的函数,消除两边的指定子串
> 替换两头的子串:
postgres=# select trim('xxxytrimyyyx','xy'); trim
postgres=# select trim(both 'xy' from 'xxxytrimyyyx'); trim
postgres=# select btrim('xxxytrimyyyx','xy'); trim
> 替换左边的子串
postgres=# select ltrim('xxxytrimyyyx','xy'); trimyyyx postgres=# select trim(leading 'xy' from 'xxxytrimyyyx'); trimyyyx
> 替换右边的子串
postgres=# select rtrim('xxxytrimyyyx','xy'); xxxytrim postgres=# select trim(trailing 'xy' from 'xxxytrimyyyx'); xxxytrim
3.抽取字符串
postgres=# select substring('helloworld',2,4); ello postgres=# select substr('helloworld',4); ello
参考地址: http://www.cnblogs.com/stephen-liu74/archive/2012/05/02/2294071.html 原文链接:https://www.f2er.com/postgresql/195411.html