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

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

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

      1. <tfoot id='d5ScQ'></tfoot>
        <legend id='d5ScQ'><style id='d5ScQ'><dir id='d5ScQ'><q id='d5ScQ'></q></dir></style></legend>
      2. 如何根据列的值展开Oracle查询的结果

        How to unfold the results of an Oracle query based on the value of a column(如何根据列的值展开Oracle查询的结果)
          • <small id='QFdyg'></small><noframes id='QFdyg'>

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

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

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

                1. 本文介绍了如何根据列的值展开Oracle查询的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Oracle DB 上有一个包含两列的表.我希望看到每一行重复的次数与存储在第二列中的数字一样多.该表如下所示:

                  I have a table on a Oracle DB with two columns. I would like to see every row repeated as many times as the number stored in the second column. The table looks like this:

                  col1 col2  
                  a    2  
                  b    3  
                  c    1
                  

                  我想写一个返回这个的查询:

                  I want to write a query that returns this:

                  col1 col2
                  a    2  
                  a    2   
                  b    3    
                  b    3    
                  b    3    
                  c    1
                  

                  所以来自 col2 的值决定了一行重复的次数.有没有简单的方法来实现这一目标?

                  So the value from col2 dictates the number of times a row is repeated. Is there a simple way to achieve this?

                  谢谢!

                  推荐答案

                  SQL Fiddle

                  Oracle 11g R2 架构设置:

                  CREATE TABLE test ( col1, col2 ) AS
                            SELECT 'a', 2 FROM DUAL
                  UNION ALL SELECT 'b', 3 FROM DUAL
                  UNION ALL SELECT 'c', 1 FROM DUAL
                  

                  查询 1:

                  SELECT col1,
                         col2
                  FROM   test t,
                         TABLE(
                           CAST( 
                             MULTISET(
                               SELECT LEVEL
                               FROM   DUAL
                               CONNECT BY LEVEL <= t.col2
                             )
                             AS SYS.ODCINUMBERLIST
                           )
                         )
                  

                  结果:

                  | COL1 | COL2 |
                  |------|------|
                  |    a |    2 |
                  |    a |    2 |
                  |    b |    3 |
                  |    b |    3 |
                  |    b |    3 |
                  |    c |    1 |
                  

                  这篇关于如何根据列的值展开Oracle查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 查询中包含缺失的月份)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  1. <legend id='12Y5E'><style id='12Y5E'><dir id='12Y5E'><q id='12Y5E'></q></dir></style></legend>

                      <bdo id='12Y5E'></bdo><ul id='12Y5E'></ul>
                          <i id='12Y5E'><tr id='12Y5E'><dt id='12Y5E'><q id='12Y5E'><span id='12Y5E'><b id='12Y5E'><form id='12Y5E'><ins id='12Y5E'></ins><ul id='12Y5E'></ul><sub id='12Y5E'></sub></form><legend id='12Y5E'></legend><bdo id='12Y5E'><pre id='12Y5E'><center id='12Y5E'></center></pre></bdo></b><th id='12Y5E'></th></span></q></dt></tr></i><div id='12Y5E'><tfoot id='12Y5E'></tfoot><dl id='12Y5E'><fieldset id='12Y5E'></fieldset></dl></div>
                            <tbody id='12Y5E'></tbody>
                        • <tfoot id='12Y5E'></tfoot>
                        • <small id='12Y5E'></small><noframes id='12Y5E'>