我有这张桌子:
id text
------- ----------------------------------------------------
128 1|abc def|2|asdfgh|qwerty|3|zxvcb|6/3/2015|2015|
128 1|asd adad|2|djfk|sdsd|3|asadd|7/3/2015|2015|
129 1|adads asad|2|saad|asda|3|asdad|8/3/2015|2015|
我希望是这样的:
id test_1 test_2 test_3
---- ------------------ --------------------- ------------------
128 1|abc def| 2|asdfgh|qwerty| 3|zxvcb|6/3/2015|2015|
128 1|asd adad| 2|djfk|sdsd| 3|asadd|7/3/2015|2015|
129 1|adads asad| 2|saad|asda| 3|asdad|8/3/2015|2015|
任何人都可以帮助我吗?
答案 0 :(得分:1)
select id, substr(text, pos1, pos2-pos1) as text1, substr(text, pos2, pos3-pos2) as text2, substr(text, pos3) as text3
from (select id, text, instr(text, '1|') pos1, instr(text, '2|') pos2, instr(text, '3|') pos3
from (
select 128 as id, '1|abc def|2|asdfgh|qwerty|3|zxvcb|6/3/2015|2015|' as text from dual union all
select 128 as id, '1|asd adad|2|djfk|sdsd|3|asadd|7/3/2015|2015|' as text from dual union all
select 129 as id, '1|adads asad|2|saad|asda|3|asdad|8/3/2015|2015|' as text from dual
)
)