Oracle splits strings to show in single-row multiline

Source: Internet
Author: User

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 results are as follows:

Field2

A
Bbb
Cccc
Ddddd
Ee
D
A

Connect by: Recursion, which is the condition for the query to continue

InStr (field1, ' | ', 2, rownum) string starting from the 2nd position, starting from a, ' | ' The delimiter from the first to the eighth appears in order: 3, 5, 7, 9, 11, 13, 15, 0, so it will be queried seven times, that is, there will be seven rows.

The second parameter of the SUBSTR function is InStr (field1, ' | ', 1, rownum) + 1, which means ' | ' Start match from first position, first to seventh match position plus one, i.e. 2, 4, 6, 8, 10, 12, 14

The third parameter of the SUBSTR function take a closer look, constant equals one.

In other words, press ' | ' After the division, the first take the second part, the second take the four parts, and so on.

The values were: A, BBB, CCCC, DDDDD, EE, D, a

Because RowNum is incremented, it becomes seven rows of data.

The analysis is complete.

Oracle splits strings to show in single-row multiline

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.