zoukankan      html  css  js  c++  java
  • 011.PGSQL-substr、substring、left、right、position、strpos

    1.substr(字符串,开始索引,截取长度)
    select SUBSTR('太阳当空照,花儿对我笑',1,4)
    太阳当空

    substr(字符串,留下的字符串索引的开始)
    select SUBSTR('太阳当空照,花儿对我笑',5)
    照,花儿对我笑

    2.substring(字符串 from 开始索引 for 截取长度)
    select SUBSTRING('太阳当空照,花儿对我笑' from 2 for 7)
    阳当空照,花儿

    3.截断后几位
    select left('太阳当空照,花儿对我笑',length('太阳当空照,花儿对我笑') -2);
    太阳当空照,花儿对

    留下右边几位
    select right('太阳当空照,花儿对我笑', 5);
    花儿对我笑

    留下左边几位
    select left('太阳当空照,花儿对我笑', 5);
    太阳当空照

    4. 正则切割 A开头,后面10位数字
    select substring('sdfgA123456789123456空间和规范fd','.*(Ad{10}).*' )
    A1234567891
    select regexp_replace('sdfgA123456789123456空间和规范fd','.*(Ad{10}).*','1','g')
    A1234567891

    5.字符在字符串的位置
      select POSITION('派出所' in 'sd56派出所空间')
      5
      select strpos('sd56派出所空间', '派出所')
      5

    6.截去指定字符的后几位
    select left('sd56派出所空间', POSITION('派出所' in 'sd56派出所空间')-1)
    select substr('sd56派出所空间',1, POSITION('派出所' in 'sd56派出所空间')-1)
    sd56

    留下指定字符及其后几位
    select right('sd56派出所空间', POSITION('派出所' in 'sd56派出所空间'))
    select substr('sd56派出所空间', POSITION('派出所' in 'sd56派出所空间') )
    派出所空间

  • 相关阅读:
    CLOUD COMPUTING MADE EASY by Cary Landis and Dan Blacharski
    浅析JSONP
    Xpages 执行的生命周期
    LotusScript类的继承
    苹果公司的UI交互设计师Bret Victor演讲 Inventing on Principle
    ajax
    Aptana 汉化方法
    删除数据库连接脚本
    让Visual Studio 也支持JS代码折叠 [ Visual Studio | #region | #endregion ]
    power designer简单教程
  • 原文地址:https://www.cnblogs.com/star521/p/13470833.html
Copyright © 2011-2022 走看看