Oracle提取字符串的问题。
有个需求,需要从一个表的一个字段中提取出需要的字段。比如
原表结构:--还有些字段。我这里就写2个就够了。
statis_date varchar2(8),
content varchar2(511)
..
..
------------------------------
其中content中的数据是这样的:
Main Product
MainProd_A change to
MainProd_B. MainProd_B effect at
20121213 142355. Appendant product list: &. Service list: &. The subscriber IMSI
605123456789 change to
805123456789 . Remaining Core Balance is
2000;
-----------------------------
我需要把红色部分分别提取出来插入到新表里面。目前我已经做了个样子,但还有更简单的办法么?求各位给个更简单的办法 ,不然数据多了。我怕性能问题。我的办法如下:
select t.statis_date,
trim(substr(t.content, 13, instr(t.content, 'change to') - 13)) as oldproduct,
trim(substr(t.content,
instr(t.content, 'to') + 2,
instr(t.content, '.') - instr(t.content, 'to') - 2)) as newproduct,
trim(substr(t.content,
instr(t.content, 'at') + 2,
instr(t.content, '.', 1, 2) - instr(t.content, 'at') - 2)) as effecttime,
trim(substr(t.content,
instr(t.content, 'IMSI') + 4,
instr(t.content, 'change to', 1, 2) - instr(t.content, 'IMSI') - 4)) as oldimsi,
trim(substr(t.content,
instr(t.content, 'change to', 1, 2)+9,
instr(t.content, '.', -1, 1) - instr(t.content, 'change to', 1, 2)-9)) as newimsi,
trim(substr(t.content,
instr(t.content, 'Balance is') + 10,
instr(t.content, ';') - instr(t.content, 'Balance is') - 10)) as balance
from tb_dw_interactlog_his_day t;
oracle
提取
------解决方案--------------------with test as (
select 'Main Produ