光标返回多行
过去几天我一直在研究这个问题,但我找不到摆脱它的方法。我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)