In Oracle, you can use the unpivot() function to achieve column switching. The SQL statement is "select field list from data set unpivot(custom column name/*column value*/ for custom column name in (List of names))".
The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.
In actual business development environments, we often encounter the need to convert columns to rows in the queried data set. So how does Oracle achieve it?
Oracle column to row conversion
Oracle column to row conversion is to convert the fields of the columns in a row into multiple rows of data according to the unique value of the row.
How to achieve column switching? You can use Oracle's own column-to-row function unpivot to perfectly solve this problem
The specific syntax structure is as follows:
select 字段列表 from 数据集 unpivot(自定义列名/*列的值*/ for 自定义列名 in (列名列表))
Example:
The conversion code code is as follows:
select stuname, coursename ,score from score_copy t unpivot (score for coursename in (英语,数学,语文))
The result is as follows:
Recommended tutorial: "Oracle Tutorial》
The above is the detailed content of What is the SQL statement for converting Oracle columns to rows?. For more information, please follow other related articles on the PHP Chinese website!