zoukankan      html  css  js  c++  java
  • PostgreSQL 判断字符串包含的几种方法

    判断字符串包含的几种方法:

    1. position(substring in string):

    postgres=# select position('aa' in 'abcd');  position  ----------         0 (1 row)  postgres=# select position('ab' in 'abcd');  position  ----------         1 (1 row)  postgres=# select position('ab' in 'abcdab');  position  ----------         1 (1 row)
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    可以看出,如果包含目标字符串,会返回目标字符串笫一次出现的位置,可以根据返回值是否大于0来判断是否包含目标字符串。

    2. strpos(string, substring): 该函数的作用是声明子串的位置。

    postgres=# select strpos('abcd','aa');  strpos  --------       0 (1 row)  postgres=# select strpos('abcd','ab');  strpos  --------       1 (1 row)  postgres=# select strpos('abcdab','ab');  strpos  --------       1 (1 row)
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    作用与position函数一致。

    3. 使用正则表达式:

    postgres=# select 'abcd' ~ 'aa';  ?column?  ----------  f (1 row)  postgres=# select 'abcd' ~ 'ab';  ?column?  ----------  t (1 row)  postgres=# select 'abcdab' ~ 'ab';  ?column?  ----------t (1 row)
  • 相关阅读:
    传统 Ajax 已死,Fetch 永生
    redux-thunk, redux-logger 阮一峰 ( react中间件 )
    flow类型检查
    svn删除项目
    svn导入项目
    ubantu搭建svn
    惠普uefi装系统
    win7跳过登陆界面
    phpstorm配置Xdebug进行调试PHP教程
    jquery 给下拉框赋值
  • 原文地址:https://www.cnblogs.com/tank-/p/8431093.html
Copyright © 2011-2022 走看看