zoukankan      html  css  js  c++  java
  • MySQL截取字符串函数方法

    函数:

      1、从左开始截取字符串

      left(str, length)

      说明:left(被截取字段,截取长度)

      例:select left(content,200) as abstract from my_content_t

      2、从右开始截取字符串

      right(str, length)

      说明:right(被截取字段,截取长度)

      例:select right(content,200) as abstract from my_content_t

      3、截取字符串

      substring(str, pos)

      substring(str, pos, length)

      说明:substring(被截取字段,从第几位开始截取)

      substring(被截取字段,从第几位开始截取,截取长度)

      例:select substring(content,5) as abstract from my_content_t

      select substring(content,5,200) as abstract from my_content_t

      (注:如果位数是负数 如-5 则是从后倒数位数,到字符串结束或截取的长度)

      4、按关键字截取字符串

      substring_index(str,delim,count)

      说明:substring_index(被截取字段,关键字,关键字出现的次数)

      例:select substring_index(”blog.chinabyte.com”,”。”,2) as abstract from my_content_t

      结果:blog.chinabyte

      (注:如果关键字出现的次数是负数 如-2 则是从后倒数,到字符串结束)

      结果:chinabyte.com

  • 相关阅读:
    Oracle EXP
    Using Spring in Web and WinForms
    System.ComponentModel(未完...)
    工作必须得到强势方的支持!
    book.Save()还是bookManager.Save(book)?
    C#中常用的Attribute搜集(刚开始...)
    领域模型是否能够屏蔽数据库?
    合格代码的最基本的标准
    关于配置系统的设计
    对象分类
  • 原文地址:https://www.cnblogs.com/sunxucool/p/3179787.html
Copyright © 2011-2022 走看看