zoukankan      html  css  js  c++  java
  • SQL截取字段字符串的方法

    set @str=‘WX15-53-H-53-99-15-335-23’;


    select @str as '字符串'


    select len(@str) as '字符长度'


    select charindex('-',@str,1) as '第一个逗号的索引值'


    select LEFT(@str,charindex('-',@str,1)-1) as '第一个值'


    select SUBSTRING(@str,charindex('-',@str,1)+1,len(@str)) as '从第一逗号开始截取出后面的字符串'


    select LEFT(SUBSTRING(@str,charindex('-',@str,1)+1,len(@str)),CHARINDEX('-',SUBSTRING(@str,charindex('-',@str,1)+1,len(@str)),1)-1) as '中间的值'


    select SUBSTRING(SUBSTRING(@str,charindex('-',@str,1)+1,len(@str)),charindex('-',SUBSTRING(@str,charindex('-',@str,1)+1,len(@str)),1)+1,len(@str)) as '第2个-后面的值’

    select SUBSTRING(SUBSTRING(@str,charindex('-',@str,2)+1,len(@str)),charindex('-',SUBSTRING(@str,charindex('-',@str,2)+1,len(@str)),2)+1,len(@str)) as '第2个-后面的值’

    select SUBSTRING(SUBSTRING(@str,charindex('-',@str,6)+1,len(@str)),charindex('-',SUBSTRING(@str,charindex('-',@str,6)+1,len(@str)),6)+1,len(@str)) as '第5个-后面的值’

    以此类推 取出的值为:15-335-23

  • 相关阅读:
    Redis 简介
    图片懒加载、selenium和PhantomJS
    Python网络爬虫之三种数据解析方式
    Scrapy框架之CrawlSpider
    Scrapy 框架
    python 网络爬虫概念与HTTP(s)协议
    Mysql概念及基本操作
    Python re 模块
    线程与进程应用场景
    全局解释器锁 GIL
  • 原文地址:https://www.cnblogs.com/jason-davis/p/5984904.html
Copyright © 2011-2022 走看看