1

因此,如果尝试运行此查询:

-- Make sure the variable is typed to a single value...
SET @my_id=300;
SELECT `my_id` INTO @my_id
FROM `my_table` WHERE `field_1`= 123 AND `field_2`IS NULL;

...然后我收到此错误:

[Err] 1172 - Result consisted of more than one row

但是,如果我运行此选择:

SELECT COUNT(*)
FROM `my_table` WHERE `field_1`= 123 AND `field_2`IS NULL;

...然后它返回零(即没有匹配)。零如何大于一?

4

1 回答 1

0

哎呀...意识到发生了什么。第一个 SELECT INTO 语句是从一个过程内部运行的,它实际调用的内容看起来更像这样:

DECLARE my_id_out INT;
DECLARE field1 INT;
DECLARE field2 INT;

-- do some stuff here to set field1 and field2 variables

SELECT `my_id` INTO my_id_out
FROM `my_table` WHERE `field_1`= field1 AND `field_2`<=> field2;

Sooo ...问题只是它使用了字段的名称,而不是我的变量的名称,并比较了field1 = field1。

只是重命名了变量,一切都很好......

于 2013-09-13T00:51:07.957 回答