代码之家  ›  专栏  ›  技术社区  ›  TSCAmerica.com

Mysql存储过程返回一些奇怪的结果

  •  1
  • TSCAmerica.com  · 技术社区  · 7 年前

    当我在SQl中运行以下select查询时

    SELECT Count(*) 
    FROM   workordercurrent 
    WHERE  office_id = 1 
           AND ( ( scheduleddate = '2018-11-01' ) 
                  OR ( schedulestopdate = '2018-11-01' ) 
                  OR ( scheduleddate = '0000-00-00' 
                       AND orderdate = '2018-11-01' ) ) 
           AND worktype <> 6 
    

    查询返回694作为正确的计数

    当我用两个输入参数在SQL过程中编写相同的查询时

    office_id(int) and order_date (DATE)
    
    
    BEGIN 
        SELECT Count(*) 
        FROM   workordercurrent 
        WHERE  office_id = office_id 
               AND ( ( scheduleddate = order_date ) 
                      OR ( schedulestopdate = order_date ) 
                      OR ( scheduleddate = '0000-00-00' 
                           AND orderdate = order_date ) ) 
               AND worktype <> 6; 
    END 
    
    It returns the count as 3260
    

    这里的问题是什么,因为两个查询完全相同。下面是我如何运行存储过程

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   Madhur Bhaiya    7 年前

    应避免使用与SP中使用的列/别名相同的存储过程参数名。 WHERE office_id = office_id 因为名字模棱两可而表现怪异。MySQL可能无法将其解析为列名或参数。

    in_ out_ inout_

    因此可以将参数重命名为 in_office_id in_order_date