MySql错误:结果由多行组成

时间:2014-02-17 13:03:42

标签: php mysql sql

我有错误:Result consisted of more than one row but i can't find out it.

条目id_user在其表中只有一条记录。

程序:

CREATE DEFINER=`root`@`localhost` PROCEDURE `delete_user_deep`(id_user int(11))
BEGIN

declare nome_loc varchar(45);
declare cognome_loc varchar(45);

select nome,cognome
into nome_loc,cognome_loc
from user
where id_user=id_user;

delete from Radius.radcheck where username in (
    select mac_address from machine where id_user =id_user);

delete from Radius.radreply where username in (
    select mac_address from machine where id_user =id_user);

delete from machine_ip where id_machine in (
    select id_machine from machine where id_user=id_user);

delete from machine where id_user = id_user;

delete from document where id_user=id_user;

delete from user where id_user=id_user;

insert into log_generic values(
                    NULL,
                    'USER',
                    'Delete User Deep',
                    (select concat ('User: ',id_user,' Name: ',cognome_loc,' Prename: ',nome_loc)),
                    now());

END

1 个答案:

答案 0 :(得分:0)

问题出在这句话中:

select nome,cognome
into nome_loc,cognome_loc
from user
where id_user=id_user;

如果有多行,这将返回错误。该错误记录在here

这是因为参数名称与列名称相同。 id_user指的是比较两侧的列。

查询应如下所示:

select nome, cognome
into nome_loc, cognome_loc
from user
where id_user = param_id_user;

始终前缀参数和变量名称,以区别于列名。