<small id='DnoFD'></small><noframes id='DnoFD'>

      <i id='DnoFD'><tr id='DnoFD'><dt id='DnoFD'><q id='DnoFD'><span id='DnoFD'><b id='DnoFD'><form id='DnoFD'><ins id='DnoFD'></ins><ul id='DnoFD'></ul><sub id='DnoFD'></sub></form><legend id='DnoFD'></legend><bdo id='DnoFD'><pre id='DnoFD'><center id='DnoFD'></center></pre></bdo></b><th id='DnoFD'></th></span></q></dt></tr></i><div id='DnoFD'><tfoot id='DnoFD'></tfoot><dl id='DnoFD'><fieldset id='DnoFD'></fieldset></dl></div>

    1. <tfoot id='DnoFD'></tfoot>
      <legend id='DnoFD'><style id='DnoFD'><dir id='DnoFD'><q id='DnoFD'></q></dir></style></legend>

      • <bdo id='DnoFD'></bdo><ul id='DnoFD'></ul>

        Oracle中如何将行转换为列?

        How to convert Rows to Columns in Oracle?(Oracle中如何将行转换为列?)
          <tbody id='KVan4'></tbody>
        <i id='KVan4'><tr id='KVan4'><dt id='KVan4'><q id='KVan4'><span id='KVan4'><b id='KVan4'><form id='KVan4'><ins id='KVan4'></ins><ul id='KVan4'></ul><sub id='KVan4'></sub></form><legend id='KVan4'></legend><bdo id='KVan4'><pre id='KVan4'><center id='KVan4'></center></pre></bdo></b><th id='KVan4'></th></span></q></dt></tr></i><div id='KVan4'><tfoot id='KVan4'></tfoot><dl id='KVan4'><fieldset id='KVan4'></fieldset></dl></div>

        • <tfoot id='KVan4'></tfoot>
          <legend id='KVan4'><style id='KVan4'><dir id='KVan4'><q id='KVan4'></q></dir></style></legend>

              <bdo id='KVan4'></bdo><ul id='KVan4'></ul>

              <small id='KVan4'></small><noframes id='KVan4'>

                  本文介绍了Oracle中如何将行转换为列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个这种形式的表格(这只是部分视图,表格包含 100 多列).

                  I have a table in this form (this is just the partial view, the table contains more than 100 columns).

                   LOAN NUMBER   DOCUMENT_TYPE                DOCUMENT_ID
                   992452533663  Voters ID                    XPD0355636
                   992452533663  Pan card                     CHXPS5522D
                   992452533663  Drivers licence              DL-0420110141769
                  

                  一个贷款号,我有三种文件作为证明.我希望将这些详细信息转换为列并采用以下形状:

                  For a single loan number, I have three kinds of documents as proof. I want these details to be converted into columns and take the following shape:

                  LOAN NUMBER     VOTERS_ID    PAN_CARD     DRIVERS LICENCE
                  992452533663    XPD0355636   CHXPS5522D   DL-0420110141769
                  

                  如何解决这个问题?

                  推荐答案

                  如果您使用的是 Oracle 10g,则可以使用 DECODE 函数将行转为列:

                  If you are using Oracle 10g, you can use the DECODE function to pivot the rows into columns:

                  CREATE TABLE doc_tab (
                    loan_number VARCHAR2(20),
                    document_type VARCHAR2(20),
                    document_id VARCHAR2(20)
                  );
                  
                  INSERT INTO doc_tab VALUES('992452533663', 'Voters ID', 'XPD0355636');
                  INSERT INTO doc_tab VALUES('992452533663', 'Pan card', 'CHXPS5522D');
                  INSERT INTO doc_tab VALUES('992452533663', 'Drivers licence', 'DL-0420110141769');
                  
                  COMMIT;
                  
                  SELECT
                      loan_number,
                      MAX(DECODE(document_type, 'Voters ID', document_id)) AS voters_id,
                      MAX(DECODE(document_type, 'Pan card', document_id)) AS pan_card,
                      MAX(DECODE(document_type, 'Drivers licence', document_id)) AS drivers_licence
                    FROM
                      doc_tab
                  GROUP BY loan_number
                  ORDER BY loan_number;
                  

                  输出:

                  LOAN_NUMBER   VOTERS_ID            PAN_CARD             DRIVERS_LICENCE    
                  ------------- -------------------- -------------------- --------------------
                  992452533663  XPD0355636           CHXPS5522D           DL-0420110141769     

                  您可以使用 11g 中引入的 Oracle PIVOT 子句实现相同的目的:

                  You can achieve the same using Oracle PIVOT clause, introduced in 11g:

                  SELECT *
                    FROM doc_tab
                  PIVOT (
                    MAX(document_id) FOR document_type IN ('Voters ID','Pan card','Drivers licence')
                  );
                  

                  带有两种解决方案的 SQLFiddle 示例:SQLFiddle 示例

                  SQLFiddle example with both solutions: SQLFiddle example

                  在此处阅读有关透视的更多信息:透视蒂姆·霍尔的甲骨文

                  Read more about pivoting here: Pivot In Oracle by Tim Hall

                  这篇关于Oracle中如何将行转换为列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  <tfoot id='qdvin'></tfoot>
                    <tbody id='qdvin'></tbody>

                  <small id='qdvin'></small><noframes id='qdvin'>

                  • <bdo id='qdvin'></bdo><ul id='qdvin'></ul>

                          <legend id='qdvin'><style id='qdvin'><dir id='qdvin'><q id='qdvin'></q></dir></style></legend>

                          1. <i id='qdvin'><tr id='qdvin'><dt id='qdvin'><q id='qdvin'><span id='qdvin'><b id='qdvin'><form id='qdvin'><ins id='qdvin'></ins><ul id='qdvin'></ul><sub id='qdvin'></sub></form><legend id='qdvin'></legend><bdo id='qdvin'><pre id='qdvin'><center id='qdvin'></center></pre></bdo></b><th id='qdvin'></th></span></q></dt></tr></i><div id='qdvin'><tfoot id='qdvin'></tfoot><dl id='qdvin'><fieldset id='qdvin'></fieldset></dl></div>