我在学习存储过程,写了以下以后很简单的例子
CREATE DEFINER=`root`@`localhost` PROCEDURE `selectbyid`(IN ID INT)
BEGIN
       SELECT * FROM  physprop where id =ID;
END
在mysql命令行里调用时却不成功
mysql>call selectbyid(3);
但是结果却是把表里所有的行都显示出来了
不知道是怎么回事,请各位帮忙看看吧,多谢了!!

解决方案 »

  1.   

    IN ID ->IN ID1
     SELECT * FROM  physprop where id =ID1; 优先处理字段名
      

  2.   

    CREATE DEFINER=`root`@`localhost` PROCEDURE `selectbyid`(IN CID INT) 
    BEGIN 
          SELECT * FROM  physprop where id = CID; 
    END 你的字段名ID和参数名ID重名了。
      

  3.   

    Important: SQL variable names should not be the same as column names. If an SQL statement, such as a SELECT ... INTO statement, contains a reference to a column and a declared local variable with the same name, MySQL currently interprets the reference as the name of a variable. For example, in the following statement, xname is interpreted as a reference to the xname variable rather than the xname column: