zoukankan      html  css  js  c++  java
  • mysql 截取字符串,以及format时间,截取时间

    年月日:如2014-04-25 08:00:00

    截取时间中的日:取出来25,

    可以使用date_format这个函数取,如图:

    相应的date_format函数使用方法可以参考下:

    http://www.w3school.com.cn/sql/func_date_format.asp

    当截取日期的时候如果使用substring,left,right,substring_index 这些函数都取不出来25,下边介绍它们的区别:

    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 则是从后倒数,到字符串结束)

  • 相关阅读:
    traceroute工具
    tcpdump抓包
    Linux 信号表 signals
    Bloom Filter (海量数据处理)
    socks v5 协议解析
    Vim插件推荐
    建堆复杂度O(n)证明
    使用Vundle管理Vim插件
    VB调用C# dll
    域PC脱域
  • 原文地址:https://www.cnblogs.com/love-you-girl/p/3878106.html
Copyright © 2011-2022 走看看