光标返回多行

发布于 2024-08-18 11:17:36 字数 698 浏览 2 评论 0原文

过去几天我一直在研究这个问题,但我找不到摆脱它的方法。我有一个 C# Web 应用程序,需要在屏幕上打印报告。该应用程序调用数据库 (Oracle) 上的存储过程并返回游标。这是程序,

PROCEDURE report_total(beginDate IN DATE, endDate IN DATE, c OUT REF CURSOR)
AS
BEGIN
   OPEN
      c
   FOR
      SELECT
          month
          ,sum(field1)
          -- + a lot of other fields
      FROM
          view1 v
      WHERE
          beginDate <= v.date
          AND v.Date < endDate
      GROUP BY
          month
END;

效果很好,它给了我每月 field1 (和其他)的总和。假设您至少输入完整的年份范围,您最多将获得 12 行。然而。我想制作一个类似的存储过程来为我提供这几个月的详细信息。

假设 beginDate = '2003-01-01' 和 endDate = '2005-01-05' (YYYY-MM-DD),我需要 25 行。每月一次,每年一次。我想用光标 OUT 来获得这些结果。如果您有一个不涉及光标的最简单的想法,请建议我。

I've been working on this for the past few days and I can't find my way out of it. I have a C# web application that needs to print reports on screen. This same application calls a stored procedure on the database (Oracle) and it returns a cursor. Here is the procedure

PROCEDURE report_total(beginDate IN DATE, endDate IN DATE, c OUT REF CURSOR)
AS
BEGIN
   OPEN
      c
   FOR
      SELECT
          month
          ,sum(field1)
          -- + a lot of other fields
      FROM
          view1 v
      WHERE
          beginDate <= v.date
          AND v.Date < endDate
      GROUP BY
          month
END;

This works fine, it gives me the sum of field1 (and others) per months. Assuming you enter, at least, a complete year range you'll get, at most, 12 rows. Howhever. I would like to make something a similar stored procedure that would give me the detail of these months.

Let's say beginDate = '2003-01-01' and the endDate = '2005-01-05' (YYYY-MM-DD), I would need 25 rows. One per month, per year. And I would like to get these results with the cursor OUT. If you have a simplest idea that wouldn't involve a cursor please suggest me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱情眠于流年 2024-08-25 11:17:36
SELECT  TRUNC(v.date, 'MONTH'), SUM(field1)
FROM    view1 v
WHERE   v.date BETWEEN beginDate and endDate
GROUP BY
        TRUNC(v.date, 'MONTH')
SELECT  TRUNC(v.date, 'MONTH'), SUM(field1)
FROM    view1 v
WHERE   v.date BETWEEN beginDate and endDate
GROUP BY
        TRUNC(v.date, 'MONTH')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文