Home>Article>Database> What is Oracle's column to row function?

What is Oracle's column to row function?

WBOY
WBOY Original
2022-01-26 10:53:55 15832browse

In Oracle, the column-to-row function is the "unpivot()" function, which is used to convert table data from column to row. The syntax is "unpivot(custom column name column value for custom column Name column name in (column name))".

What is Oracle's column to row function?

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

What is Oracle’s column-to-row function?

Oracle’s column-to-row function is the unpivot() function

The example is as follows:

Original table

What is Oracles column to row function?

with temp as( select '四川省' nation ,'成都市' 第一,'绵阳市' 第二,'德阳市' 第三,'宜宾市' 第四 from dual union all select '湖北省' nation ,'武汉市' 第一,'宜昌市' 第二,'襄阳市' 第三,'' 第四 from dual ) select nation,name,title from temp unpivot (name for title in (第一,第二,第三,第四))t

What is Oracles column to row function?

Description: unpivot(custom column name/*column value*/ for custom column name/*column name*/ in (column name))

The example is as follows:

The original data is as follows:

What is Oracles column to row function?

And the result I want to get is as follows:

What is Oracles column to row function?

##SQL:

select class_name, student_name, course_type, result, created_date from class_tmp unpivot(result for course_type in(chinese_result,math_result));

The column names of the chinese_result column and math_result column of the original data will be converted into the field value of the new column course_type, indicating the course type.

The field values of the chinese_result column and math_result column of the original data will be converted into the field values of the new column result, representing scores.

Recommended tutorial: "

Oracle Video Tutorial"

The above is the detailed content of What is Oracle's column to row function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to delete oracle field Next article:How to delete oracle field