substr( string, start_pos, [ length ] )
如:
substr('This is a test', 6, 2) would return 'is'
substr('This is a test', 6) would return 'is a test'
substr('TechOnTheNet', -3, 3) would return 'Net'
substr('TechOnTheNet', -6, 3) would return 'The'
select substr('Thisisatest', -4, 2) value from dual结果是 te
select substr('emros',-3,1) value from dual 结果是 r
substr('abcde',-6) = null
substr('abcde',-5) = 'abcde'
substr('abcde',-4) = 'bcde'
substr('abcde',-3) = 'cde'
substr('abcde',-2) = 'de'
substr('abcde',-1) = 'e'
substr('abcde',-0) = 'abcde'
selectsubstr('a123456',instr('a123456','a')+1,len('a123456')-instr('a123456','a'))
from
dual
instr
返回1,
所以给它+1
,
从第2位开始截取到总长度-‘a’这个字符串的位置,
就是
6
,
所以最终会是
select
substr('a123456',2,6)
from
dual
这么写能明白吗?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)