Oracle 11g行列轉換之UNPIVOT

來源:互聯網
上載者:User

Oracle 11g提供了新的行列轉換操作:PIVOT(行轉列)和UNPIVOT列轉行。本文對UNPIVOT的功能進行展示。

現有表src_table如下:

product_Id(產品ID) product_color(顏色) porduct_type(型號) is_intelligent(是否智能)
1111 red t1 是
1112 blue t2 否
1113 green t3 是

目標表dest_table如下:

product_Id param_name(參數名稱) param_value(參數值)
1111 product_color red
1112 product_color blue
1113 product_color green
1111 product_type t1
1112 product_type t2
1113 product_type t3
1111 is_intelligent 是
1112 is_intelligent 否
1113 is_intelligent 是

通過UNPIVOT實現如下:

SELECT *  
FROM   src_table  
UNPIVOT (param_value FOR param_name IN (product_color AS 'product_color', product_type AS 'product_type', is_intelligent AS 'is_intelligent');

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.