select substr('abcdefg12345',1,5) as 输出值 from dual;
--输出结果为:abcde
select substr('abcdefg12345',0,5) as 输出值 from dual;
--输出结果为:abcde
--前两个语句说明0和1都表示截取的位置为第一个字符
select substr('abcdefg12345',4,6) as 输出值 from dual;
--输出结果为:defg12
select substr('abcdefg12345',-5,2) as 输出值 from dual;
--输出结果为:12
select substr('abcdefg12345',3) as 输出值 from dual;
--输出结果为:cdefg12345
select substr('abcdefg12345',-3) as 输出值 from dual;
--输出结果为:345
select instr('12/42/56','/',1,1) from dual;
--输出结果为:3
select instr('12/42/56','/',7,1) from dual;
--输出结果为:0 查不到,则返回0
select instr('12/42/56','/',-1,1) from dual;
--输出结果为:6
select instr('12/42/56','/') from dual;
--输出结果为:3 默认‘/’第一次出现的位置
select instr('12/42/56','/4') from dual;'
--输出结果为:3
注: 空格也是字符,instr()函数的起始位置不能为0,否则返回结果为0;
字段值为json形式,变更其中某个值
SELECT substr('{"CSZDMC1":"","CSZDMC2":"12021405100906","CSZDMC":"123456","CSZDMC3":"1"}',
instr('{"CSZDMC1":"","CSZDMC2":"12021405100906","CSZDMC":"123456","CSZDMC3":"1"}', ',', 1, 2) + 11,
instr('{"CSZDMC1":"","CSZDMC2":"12021405100906","CSZDMC":"123456","CSZDMC3":"1"}', ',', 1, 3)
- instr('{"CSZDMC1":"","CSZDMC2":"12021405100906","CSZDMC":"123456","CSZDMC3":"1"}', ',', 1, 2) - 12)
FROM DUAL;
--查询结果为:123456