# MID

从字符串中指定的起始位置起返回指定长度的字符串,用法与SUBSTR函数相同。

# 语法

MID(str, start_index, [num])

  • str:给定的字符串对象
  • start_index:非负整数,规定要提取的子串的第一个字符在str中的位置。合法取值范围是1len(str)
    • start_index>0:在字符串的指定位置开始
    • start_index<0:从字符串结尾的指定位置开始
    • start_index=0:返回空字符串
    • start_index>len(str):返回空字符串
    • start_index+num>len(str):返回的子串一直到字符串的结尾
  • num:可选的非负整数,返回子串的长度
    • 合法取值范围:1len(str)-start_index+1
    • 不传递参数时:返回的子串会一直到字符串的结尾
    • num<1:返回空字符串

示例地址: MID (opens new window)

# 示例

  1. MID("qwer",2) 从第二个字符一直到字符串尾,返回wer
  2. MID("210502198412020944",7,8) 返回身份证中的出生日期,返回19841202
  3. MID("03-武汉店",1,FIND("03-武汉店",'-')-1) 返回门店编码,返回03 FIND函数
  4. MID(A1,1,4) 静态值返回生产季节的年份,返回2017
  5. MID([门店销售明细表].[生产季节],1,4) 参数值返回生产季节的年份,返回2017
  6. MID("asd",0,2) start_index=0,返回结果为空字符串
  7. MID("asd",4,2) start_index超过字符串长度,返回结果为空字符串
  8. MID("abcdefg",-1,4) start_index<0,返回结果从字符串结尾的指定位置开始,返回g
  9. MID("asd",1,4) num超过字符串长度,返回字串一直到字符串的结尾,返回asd
  10. MID("asd",2,0) num=0,返回结果为空字符串
  11. MID("asd",2,-1) num<1,返回结果为空字符串
  12. MID("湖北省武汉市",5,3) start_index+num>len(str),返回子字符串一直到结尾,返回汉市
是否有帮助?
0条评论
评论