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查询的结果

        时间:2024-04-16
          • <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查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 regexp_substr 在 Oracle 中按空格和字符作为分隔符拆分字符串 下一篇:使用 oracle SQL 按分隔符位置拆分字符串

                  相关文章

                  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>
                  2. <tfoot id='12Y5E'></tfoot>
                  3. <small id='12Y5E'></small><noframes id='12Y5E'>