不知道为什么这让我感到困惑。.奇怪的是,我看到的操作方法显示为工作台中的错误。
所以我想先选择var并选择next ..然后使用var更新..但是
它永远都行不通..所以我发现您必须执行插入操作..现在它上面显示红色x ..这有什么问题呢?

    use reunionfunfacts;
drop procedure if exists reunionfunfacts.getTrueFact;
DELIMITER //


CREATE PROCEDURE getTrueFact(in in_idperson int)

BEGIN
DECLARE _idtrue_fact    int;

select
    idtrue_fact into _idtrue_fact,
    fact_text
from
    reunionfunfacts.true_fact
where
    in_idperson = idperson and fact_in_use = 0 or fact_in_use is null
order by rand() limit 1;


update reunionfunfacts.true_fact set fact_in_use=1 where idtrue_fact=_idtrue_fact;
END
//

DELIMITER ;

最佳答案

您有2列,因此必须像这样添加到INTO变量中

但我不知道TEXT是否足以满足您的事实文本

drop procedure if exists reunionfunfacts.getTrueFact;
DELIMITER //


CREATE PROCEDURE getTrueFact(in in_idperson int)

BEGIN
DECLARE _idtrue_fact    int;
DECLARE _fact_text    TEXT;

select
    idtrue_fact ,
    fact_text
    INTO _idtrue_fact, _fact_text
from
    reunionfunfacts.true_fact
where
    in_idperson = idperson and fact_in_use = 0 or fact_in_use is null
order by rand() limit 1;


update reunionfunfacts.true_fact set fact_in_use=1 where idtrue_fact=_fact_text;
END
//

DELIMITER ;

10-04 11:46