After the oracle splits the string, it is displayed in a single column and multiple rows in oracle.

Source: Internet
Author: User

After the oracle splits the string, it is displayed in a single column and multiple rows in oracle.

Original SQL:

Select substr (field1, instr (field1, '|', 1, rownum) + 1, instr (field1, '|', 1, rownum + 1)-instr (field1, '|', 1, rownum)-1) as field2 from (select '| 'a | bbb | cccc | ddddd | ee | d | a' |' as field1 from dual) connect by instr (field1, '|', 2, rownum)> 0;

The query result is as follows:

Field2

A
Bbb
Cccc
Ddddd
Ee
D
A

Connect by: recursion, that is, the condition for continued Query

The instr (field1, '|', 2, rownum) string starts from the second position, that is, from a, and the '|' separator appears from the first time to the eighth time in sequence: 3, 5, 7, 9, 11, 13, 15, 0, so there will be seven queries, that is, there will be seven rows.

The second parameter of the substr function is instr (field1, '|', 1, rownum) + 1, indicating '|' matching starts from the first position, add the first to the seventh matching position, that is, 2, 4, 6, 8, 10, 12, and 14.

The third parameter of the substr function is always equal to 1.

That is to say, after dividing by '|', take the second part for the first time, take the fourth part for the second time, and so on.

The values are as follows: a, bbb, cccc, ddddd, ee, d, and.

Because rownum is incremental, it turns into seven rows of data.

The analysis is complete.

 

 

 

 

Related Article

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.