加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL 相似字符串函数和操作符对比

发布时间:2020-12-13 17:22:56 所属栏目:百科 来源:网络整理
导读:postgresql字符串函数的相似功能函数对比: 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 可以

postgresql字符串函数的相似功能函数对比:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读