问题描述
我需要编写一份报告,根据每个记录的日期范围生成汇总表.
I need to write a report that generates summary totals against a table with date ranges for each record.
我想要的基本上是这样的:
What I want out is basically this:
我很难弄清楚如何迭代一个日期范围.我确信这是一些可以为此创建的简单游标,但我不知所措.最好在 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):
这篇关于如何在 PL/SQL 中迭代日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!