微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

原文地址:https://www.jb51.cc/postgresql/195411.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐