Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Multi-column switching in oracle

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Method 1: through the wm_concat function, this function can be used in 10g, not compatible in 11g, removed from 12g, and the return type is varchar.

Syntax: wm_concat (column)

Example: Select wm_concat (Rownum) From dual Connect By Rownum < 10

Advantages: simple syntax

Disadvantages: character length can not exceed 4000, separated by commas, if you want to be separated by other symbols, but also replace, the performance is relatively poor

Method 2: through lisagg, the return type is varchar

Syntax: listagg (parameter, 'delimiter') within group (order by parameter id)

Example: Select

Listagg (Rownum,';') Within group (Order By Rownum Desc)

From dual Connect By Rownum < 10

Advantages: it can be sorted, and the delimiters can be customized, and it is efficient.

Disadvantages: the length of stitching characters cannot exceed 4000

Method 3: through xmlagg, it is used to parse MXL, or it can be used as character concatenation to return the clob type.

Syntax:

XMLAGG (XMLPARSE (CONTENT field | | WELLFORMED) ORDER BY field) .GETCLOBVAL ()

Or

XMLAGG (XMLELEMENT (e, string, delimiter) .Extract ('/ / text ()') .GETCLOBVAL ()

Example:

You can use either of the following:

Select Xmlagg (Xmlparse (Content Rownum | |', 'Wellformed) Order By Rownum Desc)

.Getclobval ()

From Dual

Connect By Rownum < 30000

Select Xmlagg (Xmlelement (e, Rownum,','). Extract ('/ / text ()') .Getclobval ()

From Dual

Connect By Rownum < 30

Advantages: there is no length limit for character stitching

Disadvantages: syntax is complex.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report