MYSQL 错误:PROCEDURE 无法在给定上下文中返回结果集

发布于 2024-09-10 23:09:53 字数 890 浏览 2 评论 0原文

我是 mysql 中的存储过程的新手,

这是返回不包括周末的日期差异的过程,但它返回错误

#1312 - PROCEDURE blog1.DayCount 无法在给定上下文中返回结果集

是程序

DROP PROCEDURE IF EXISTS daycount; 
CREATE PROCEDURE DayCount( d1 DATE, d2 DATE ) 
SELECT dd.iDiff, dd.iDiff - dd.iWeekEndDays AS iWorkDays, dd.iWeekEndDays 
FROM ( 
  SELECT 
    dd.iDiff, 
    ((dd.iWeeks * 2) +  
    IF(dd.iSatDiff >= 0 AND dd.iSatDiff < dd.iDays, 1, 0) +  
    IF (dd.iSunDiff >= 0 AND dd.iSunDiff < dd.iDays, 1, 0)) AS iWeekEndDays 
  FROM ( 
    SELECT 
      dd.iDiff, 
      FLOOR(dd.iDiff / 7) AS iWeeks, 
      dd.iDiff % 7 iDays, 
      5 - dd.iStartDay AS iSatDiff, 
      6 - dd.iStartDay AS iSunDiff 
    FROM ( 
      SELECT 
        1 + DATEDIFF(d2, d1) AS iDiff, 
        WEEKDAY(d1) AS iStartDay 
      ) AS dd 
  ) AS dd 
) AS dd ; 


CALL DayCount( '2009-8-1','2009-9-15'); 

I am new to Stored procedure in mysql

This is the procedure for returning difference of date excluding Weekends, but it returns error

#1312 - PROCEDURE blog1.DayCount can't return a result set in the given context

This is the procedure

DROP PROCEDURE IF EXISTS daycount; 
CREATE PROCEDURE DayCount( d1 DATE, d2 DATE ) 
SELECT dd.iDiff, dd.iDiff - dd.iWeekEndDays AS iWorkDays, dd.iWeekEndDays 
FROM ( 
  SELECT 
    dd.iDiff, 
    ((dd.iWeeks * 2) +  
    IF(dd.iSatDiff >= 0 AND dd.iSatDiff < dd.iDays, 1, 0) +  
    IF (dd.iSunDiff >= 0 AND dd.iSunDiff < dd.iDays, 1, 0)) AS iWeekEndDays 
  FROM ( 
    SELECT 
      dd.iDiff, 
      FLOOR(dd.iDiff / 7) AS iWeeks, 
      dd.iDiff % 7 iDays, 
      5 - dd.iStartDay AS iSatDiff, 
      6 - dd.iStartDay AS iSunDiff 
    FROM ( 
      SELECT 
        1 + DATEDIFF(d2, d1) AS iDiff, 
        WEEKDAY(d1) AS iStartDay 
      ) AS dd 
  ) AS dd 
) AS dd ; 


CALL DayCount( '2009-8-1','2009-9-15'); 

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

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

发布评论

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

评论(1

厌倦 2024-09-17 23:09:53

在 mysql 控制台中检查这个存储过程,如果它工作正常,您应该检查来自 PHP 的调用。
我发现其他人也发生了同样的问题

Check this stored proc in mysql console, if it works fine you should check your call from PHP.
I found that same problem is happen with other people.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文