• <legend id='cN6pZ'><style id='cN6pZ'><dir id='cN6pZ'><q id='cN6pZ'></q></dir></style></legend>

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

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

        <tfoot id='cN6pZ'></tfoot>

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

        如何在 PL/SQL 中迭代日期范围

        How to iterate over a date range in PL/SQL(如何在 PL/SQL 中迭代日期范围)

              <tbody id='wq2ip'></tbody>
            <legend id='wq2ip'><style id='wq2ip'><dir id='wq2ip'><q id='wq2ip'></q></dir></style></legend>
          1. <small id='wq2ip'></small><noframes id='wq2ip'>

          2. <tfoot id='wq2ip'></tfoot>

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

                  本文介绍了如何在 PL/SQL 中迭代日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要编写一份报告,根据每个记录的日期范围生成汇总表.

                  I need to write a report that generates summary totals against a table with date ranges for each record.

                  table data:
                  option   start_date   end_date
                  opt1     6/12/2009    6/19/2009
                  opt1     6/3/2009     6/13/2009
                  opt2     6/5/2009     6/6/2009
                  

                  我想要的基本上是这样的:

                  What I want out is basically this:

                  date       option    count
                  6/1/2009   opt1      0
                  6/1/2009   opt2      0
                  6/2/2009   opt1      0
                  6/2/2009   opt2      0
                  6/3/2009   opt1      0
                  6/3/2009   opt2      1
                  

                  我很难弄清楚如何迭代一个日期范围.我确信这是一些可以为此创建的简单游标,但我不知所措.最好在 PL/SQL 中

                  I am having a hard time figuring out how to iterate over a date range. I am sure this is some simple cursor that could be created for this but I am at a loss. Preferably in PL/SQL

                  更新:

                  我最终使用了此处的示例来完成我想要的去做.这将创建一个生成日期表的函数.

                  I ended up using the example here to accomplish what I wanted to do. This creates a function that generates a table of dates.

                  推荐答案

                  您将需要某种日历来循环遍历日期范围.我已经使用 按级别连接 技巧.然后,您可以将您的数据加入日历(交叉加入,因为即使当天没有选项,您也需要一行):

                  You will need some sort of calendar to loop through a range of date. I have built one using the connect by level trick. You can then join the calendar with your data (cross join since you want a row even when there is no option for that day):

                  SQL> WITH calendar AS (
                    2     SELECT to_date(:begin_date, 'mm/dd/yyyy') + ROWNUM - 1 c_date
                    3       FROM dual
                    4      CONNECT BY LEVEL <= to_date(:end_date, 'mm/dd/yyyy') 
                                               - to_date(:begin_date, 'mm/dd/yyyy') + 1
                    5  )
                    6  SELECT c_date "date", d_option "option", COUNT(one_day)
                    7    FROM (SELECT c.c_date, d.d_option,
                    8                  CASE
                    9                     WHEN c.c_date BETWEEN d.start_date AND d.end_date THEN
                   10                      1
                   11                  END one_day
                   12             FROM DATA d, calendar c)
                   13   GROUP BY c_date, d_option
                   14  ORDER BY 1,2;
                  
                  date        option COUNT(ONE_DAY)
                  ----------- ------ --------------
                  01/06/2009  opt1                0
                  01/06/2009  opt2                0
                  02/06/2009  opt1                0
                  02/06/2009  opt2                0
                  03/06/2009  opt1                1
                  03/06/2009  opt2                0
                  04/06/2009  opt1                1
                  04/06/2009  opt2                0
                  05/06/2009  opt1                1
                  05/06/2009  opt2                1
                  06/06/2009  opt1                1
                  06/06/2009  opt2                1
                  
                  12 rows selected
                  

                  这篇关于如何在 PL/SQL 中迭代日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to redirect the output of DBMS_OUTPUT.PUT_LINE to a file?(如何将 DBMS_OUTPUT.PUT_LINE 的输出重定向到文件?)
                  How do I get column datatype in Oracle with PL-SQL with low privileges?(如何使用低权限的 PL-SQL 在 Oracle 中获取列数据类型?)
                  Get a list of all functions and procedures in an Oracle database(获取 Oracle 数据库中所有函数和过程的列表)
                  Why cannot I create triggers on objects owned by SYS?(为什么我不能在 SYS 拥有的对象上创建触发器?)
                  Returning result even for elements in IN list that don#39;t exist in table(即使对于表中不存在的 IN 列表中的元素也返回结果)
                  Reset Sequence in oracle 11g(oracle 11g 中的重置序列)

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

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