查某个字段中的特定位置中的内容,如班组中的存的一些xml文档。
我选用了db2的locate函数,该函数返回在给定字符串中 第一次出现特定子串的位置,通过locate函数我得到了特定字符串的开始和结束位置,在用substr截取,就ok了
下面是实现的两种方法,方法一和方法二没有质的区别
--方法一
select substr(
substr(notecontent,200,100),
6+locate('<形式>',substr(notecontent,200,100)),
locate('</形式>',substr(notecontent,200,100))-6-locate('<形式>',substr(notecontent,200,100)))
from USERID.T_NOTE_CULTURE
--方法二
with temp as(
select NOTEID,
locate('<形式>',substr(notecontent,200,100)) as begin,
locate('</形式>',substr(notecontent,200,100)) as lth
from
userid.T_note_culture
)
select temp.begin,temp.lth,substr(notecontent,205+temp.begin,temp.lth-temp.begin-6)
from temp ,userid.T_note_culture a where a.noteid=temp.noteid