Oracle row-to-column analysis functions

Source: Internet
Author: User

Oracle row to column first look at the source data:

Method One: Wm_concat group By this method is not a problem .

SELECT code_ts,             1 ' : ' | | ELEMENT) ELEMENT        where code_ts='020745'  Group by Code_ts;

The results obtained:

You may find that the serial numbers are not sorted in order. If there is no demand, then it is possible. See method Two if you want to sort.

Method Two: Wm_concat over with special data will be error. "Operation value exceeds the system limit". cause I don't know, who knows trouble tell me about it.

Select  from (     SELECT code_ts,            1':' | | ELEMENT) Over (order by S_num) ELEMENT,             To_number (Dense_rank ()-Over                       (PARTITION by Code_ts ORDER by S_num DESC)) orderno< c12/>where code_ts='020745'  ORDER by Code_ts,s_num                 where t.orderno=1;
Wm_concat over

If the result is not error:

Method Three: Sys_connect_by_path over this method is not a problem . But note : Sys_connect_by_path The connection symbol here do not use commas , Oracle will error, if necessary to use, you can replace with replace; The connector cannot be present in your first parameter sequence . You can use multiple combinations of connector characters.

It's not easy to exist in your column, I use it here, plus a space. Of course you can also use a combination connector that does not exist, and then replace the unwanted part of the connector with the

SelectCode_ts,element from (        Selectcode_ts,element, Row_number () over (partition by code_ts ORDER BY Code_ts,rank Desc) Ename_path_rank from (        SelectCode_ts,rank, LTrim (Sys_connect_by_path (rank||':'|| ELEMENT,'; '),'; ') ELEMENT from                 (                   SelectCode_ts,element,row_number () over (partition by code_ts ORDER BY s_num desc) rank fromT_merch_elementwherecode_ts='020745'ORDER BY s_num desc) Connect by Code_ts= Prior code_ts and rank-1=prior rank)) whereename_path_rank=1;
Sys_connect_by_path

Effects such as:

Oracle row-to-column analysis functions

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.