substr 下标从0 开始
instr 返回的数值,从1开始
oracle字符串处理
select substr(memo,instr(memo,'hourid=',1)+1,instr(memo,'&',instr(memo,'=',1)+1)-instr(memo,'=',1)-1) from ZCSTATITEM t where memo is not null and memo like'%hourid%' and substr(memo,instr(memo,'&',1)+1,instr(memo,'&',instr(memo,'&',1)+1)-instr(memo,'&',1)-1) is not null
select t.memo, substr(memo,instr(memo,'=',1,2)+1,instr(memo,'&',1,2)) from ZCSTATITEM t where memo is not null and memo like '%hourid%'
select substr(memo,instr(memo,'=',2),4) from ZCSTATITEM
-- CA-CA1344-A-11OCT141250-D
select instr('CA-CA1344-A-11OCT141250-D','-',1,1) from dual;
select instr('CA-CA1344-A-11OCT141250-D','-',instr('CA-CA1344-A-11OCT141250-D','-',1)+1)-instr('CA-CA1344-A-11OCT141250-D','-',1)-1 from dual
select substr(name,instr(name,'-',1)+1,instr(name,'-',instr(name,'-',1)+1)-instr(name,'-',1)-1) from dual;
select substr(name,instr(name,'-',1,1)+1,instr(name,'-',1,2)-1-instr(name,'-',1,1)) from dual;
例子
CA-CA1344-A-11OCT141250-D
select substr(name,instr(name,'-',1)+1,instr(name,'-',instr(name,'-',1)+1)-instr(name,'-',1)-1) from test;
select substr(name,instr(name,'-',1,1)+1,instr(name,'-',1,2)-1-instr(name,'-',1,1)) from test;
六:接下我们再写一下,取第二个"-"到第三个"-"之间的字符串的方法:
select substr(name,instr(name,'-',2,2)+1,instr(name,'-',2,3)-1-instr(name,'-',2,2)) from test;