Home  >  Article  >  Database  >  MYSQL存储过程发生Result consisted of more than one r...解决_MySQL

MYSQL存储过程发生Result consisted of more than one r...解决_MySQL

WBOY
WBOYOriginal
2016-06-01 13:29:361258browse

bitsCN.com

MYSQL存储过程发生Result consisted of more than one r...

 

摘要: MYSQL存储过程错误

 

SELECT … INTO …

 

这个SELECT语法把选定的列直接存储到变量。因此,只有单一的行可以被取回。

 

在使用的时候,要注意,加上LIMIT 1

 

SELECT id,data INTO x,y FROM topic LIMIT 1;

 

另外,这种赋值语句还有个规矩就是参数名和字段名不能冲突,不然能够执行过去,但是却没有给参数赋值,这是个很隐性的错误,可以参考手册上的:

 

重要: SQL变量名不能和列名一样。如果SELECT ... INTO这样的SQL语句包含一个对列的参考,并包含一个与列相同名字的局部变量,MySQL当前把参考解释为一个变量的名字。

 

DELIMITER //CREATE PROCEDURE mytopic (        topicId INT(4),        title VARCHAR(50)        )  BEGIN        SELECT topicId,title     INTO topicId,title           FROM tbl_topic limit 1;  END//DELIMITER ;

 

当这个程序被调用的时候,无论topicId,title列的值是什么,变量newname将返回值‘NULL’。 

 

即:CALL mytopic(@topicId,@title);SELECT @topicId,@title;显示结果:@topicId  @titleNULL        NULL

 


bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn