表tx_content 有两个字段
id int,content varchar2(200)
并且表里面有如下数据
insert into tx_content values(1,'临时解决方案:你的态度确定
最终解决方案:搞定了');
-------注: 中间有回车
insert into tx_content values(2,'临时解决方案:DDP');
insert into tx_content values(3,'临时解决方案:SYS
最终解决方案:ETTTT')想得到如下数据
ID 临时解决方案 最终解决方案
1 你的态度确定 搞定了
2 DDP
3 SYS ETTTT请问用sql如何实现请大家帮忙
id int,content varchar2(200)
并且表里面有如下数据
insert into tx_content values(1,'临时解决方案:你的态度确定
最终解决方案:搞定了');
-------注: 中间有回车
insert into tx_content values(2,'临时解决方案:DDP');
insert into tx_content values(3,'临时解决方案:SYS
最终解决方案:ETTTT')想得到如下数据
ID 临时解决方案 最终解决方案
1 你的态度确定 搞定了
2 DDP
3 SYS ETTTT请问用sql如何实现请大家帮忙
instr('临时解决方案:你的态度确定 最终解决方案:搞定了','最终解决方案')-1),
'临时解决方案:',''),
replace(substr('临时解决方案:你的态度确定 最终解决方案:搞定了',
instr('临时解决方案:你的态度确定 最终解决方案:搞定了','最终解决方案'),length('临时解决方案:你的态度确定 最终解决方案:搞定了')-instr('临时解决方案:你的态度确定 最终解决方案:搞定了','最终解决方案')+1),
'最终解决方案:','')
from dual--如果有回车行,可以先replace一下!
insert into tx_content values(1,'临时解决方案:你的态度确定
最终解决方案:搞定了');
insert into tx_content values(2,'临时解决方案:DDP');
insert into tx_content values(3,'临时解决方案:SYS
最终解决方案:ETTTT');SELECT 1 n, 'ID', '临时解决方案', '最终解决方案'
FROM dual
UNION
SELECT 2,
to_char(id),
substr(content,
8,
decode(instr(content, chr(10), 1, 1),
0,
length(content),
instr(content, chr(10), 1, 1)-8)),
decode(instr(content, ':', 1, 1), 0, NULL, substr(content, instr(content, ':', 1, 1) + 1))
FROM tx_content
ORDER BY n;N 'ID' '临时解决方案' '最终解决方案'
1 ID 临时解决方案 最终解决方案
2 1 你的态度确定 搞定了
2 2 DDP
2 3 SYS ETTTT
select replace(substr(content,1,
instr(content,'最终解决方案')-1),
'临时解决方案:','') AA,
replace(substr(content,
instr(content,'最终解决方案'),length(content)-instr(content,'最终解决方案')+1),
'最终解决方案:','') VV
from tx_content
得到的数据不对吧?
第二个的最终解决方案的数据为 临时解决方案:你的态度确定 这个貌似是临时方案的哦???
create table tx_content(id int,content varchar2(200));insert into tx_content values(1,'临时解决方案:你的态度确定 最终解决方案:搞定了');
-------注: 中间有回车
insert into tx_content values(2,'临时解决方案:DDP');
insert into tx_content values(3,'临时解决方案:SYS 最终解决方案:ETTTT');select
id,
substr(content,instr(content,':')+1,instr(content||'最终解决方案','最终解决方案')-1-7) as 临时解决方案,
substr(content,instr(content||'最终解决方案:','最终解决方案:')+7,length(content)-instr(content,'最终解决方案:') ) as 最终解决方案
from tx_content;
ID 临时解决方案 最终解决方案
1 你的态度确定 搞定了
2 DDP
3 SYS ETTTT 我新手,没用考虑回车换行的情况
substr(content,instr(to_single_byte(content),':')+1,
instr(to_single_byte(content),'最终解决方案')-(instr(to_single_byte(content),':')+1))
end 最终解决方案,
case when instr(to_single_byte(content),'最终解决方案') = 0 then
substr(content,instr(to_single_byte(content),':')+1,length(to_single_byte(content))-(instr(to_single_byte(content),':')))
end 临时解决方案
from tx_content