zoukankan      html  css  js  c++  java
  • mysql 截取字符串 函数

    文章摘取自http://www.cnblogs.com/zdz8207/p/3765073.html

    练习截取字符串函数(五个)

    mysql索引从1开始

    一、mysql截取字符串函数

    1、left(str,index) 从左边第index开始截取

    2、right(str,index)从右边第index开始截取

    3、substring(str,index)当index>0从左边开始截取直到结束  当index<0从右边开始截取直到结束  当index=0返回空

    4、substring(str,index,len) 截取str,从index开始,截取len长度

    5、substring_index(str,delim,count),str是要截取的字符串,delim是截取的字段 count是从哪里开始截取(为0则是左边第0个开始,1位左边开始第一个选取左边的,-1从右边第一个开始选取右边的

    6、subdate(date,day)截取时间,时间减去后面的day

    7、subtime(expr1,expr2)  时分秒expr1-expr2

    二、mysql截取字符串的一些栗子

    1、left(str,index)  index>=0 从左边开始截取

    2、right(str,index)  index>=0 从右边开始截取

    3、substring(str,index) =SUBSTRING(str FROM pos) 包括index这个位置的字符

     

    4、substring(str,index,len) 截取str,从index开始,截取len长度

     

    5、substring_index(str,delim,count),str是要截取的字符串,delim是截取的字段 count是从哪里开始截取(为0则是左边第0个开始,1位左边开始第一个选取左边的,-1从右边第一个开始选取右边的

    为1,从左边开始数第一个截取,选取左边的值

    为-1,从右边开始数第一个截取,选取右边的值

    特殊情况,字符串中没有指定的字符,则返回原字符串(index=0时候例外)

     6、subdate(date,day)截取时间,时间减去后面的day

     7、subtime(expr1,expr2)--是两个时间相减

    趁年轻,撸起袖子加油干
  • 相关阅读:
    BestCoder Round #65 hdu5590(水题)
    codeforces Ebony and Ivory(水题)
    codeforces 630B Moore's Law
    BestCoder Round #69 (div.2)(hdu5611)
    BestCoder Round #73 (div.2)(hdu 5630)
    codeforces 630A Again Twenty Five!
    codeforces 630C Lucky Numbers
    codeforces 630D Hexagons!
    Codeforces243C-Colorado Potato Beetle(离散化+bfs)
    hdu4453-Looploop(伸展树)
  • 原文地址:https://www.cnblogs.com/jwanqiang/p/10267138.html
Copyright © 2011-2022 走看看