Row-to-Column

Source: Internet
Author: User

9i
-- Multiple rows
With temp
(Select '1970 1600302,6001600303, 100' text from dual
Union
Select '2014 1600302,7001600303' text from dual
)
Select substr (text, instr (text, ',', 1, RN) + 1, instr (text, ',', 1, rn + 1)-instr (text, ',', 1, RN)-1) text from
(
Select ',' | t1.text | ', 'text, t2.rn from
(Select text, length (text)-length (replace (text, ',', '') + 1 rn from temp) T1,
(Select rownum rn from all_objects where rownum <= (select max (length (text)-length (replace (text, ',', '') + 1) rn from temp) T2
Where t1.rn> = t2.rn order by text, Rn
)

Text
6001600301
6001600302
6001600303
6001600304
7001600301
7001600302
7001600303


-- Single row
With temp
(Select '2014 1600302,6001600303, 100' text from dual)
Select substr (text, instr (text, ',', 1, RN) + 1, instr (text, ',', 1, rn + 1)-instr (text, ',', 1, RN)-1) text from
(
Select ',' | t1.text | ', 'text, t2.rn from temp T1,
(Select rownum rn from all_objects where rownum <= (select length (text)-length (replace (text, ',') + 1 from temp) T2
)

Text
6001600301
6001600302
6001600303
6001600304


10 GB
-- Multiple rows
With temp
(Select '1970 1600302,6001600303, 100' text from dual
Union
Select '2014 1600302,7001600303' text from dual
)
Select regexp_substr (text, '[0-9] +', 1, RN) text from
(
Select t1.text, t2.rn from
(Select text, length (text)-length (replace (text, ',', '') + 1 rn from temp) T1,
(Select level RN from dual connect by rownum <= (select max (length (text)-length (replace (text, ',') + 1) rn from temp) T2
Where t1.rn> = t2.rn order by text, Rn
)

Text
6001600301
6001600302
6001600303
6001600304
7001600301
7001600302
7001600303


-- Single row
With temp
(Select '2014 1600302,6001600303, 100' text from dual)
Select regexp_substr (text, '[0-9] +', 1, RN) text from temp T1,
(Select level RN from dual connect by rownum <= (select length (text)-length (replace (text, ',') + 1 from temp) T2

Text
6001600301
6001600302
6001600303
6001600304
Source: http://www.itpub.net/thread-1145824-1-1.html>  


From Weizhi note (wiz)

Row-to-Column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.