【问题标题】:mysql workbench select and select into issuemysql工作台选择并选择问题
【发布时间】:2019-11-01 14:32:20
【问题描述】:

不知道为什么这让我感到困惑..奇怪的是,我看到的如何做到这一点的事情在工作台中显示为错误.. 所以我想先选择 var 然后选择下一个 .. 然后使用 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 ;

【问题讨论】:

  • SQL Server 和 MySQL 是完全不同的产品。您不能将 MySQL Workbench 与 SQL Server 一起使用,也不能将 SSMS 与 MySQL 一起使用
  • 你的标题是“mysql workbench”,但你的标签是sql-server
  • 您是否尝试将一列选择为 2 个变量?你能改写一下'所以我想先选择 var 然后选择下一个' fact_text 的用途是什么,你似乎没有使用它。
  • 我没有混合使用 sql 和 mysql.. 都是 mysql。我没有尝试为 sql-server 添加标签.. 抱歉.. 所以我想将 idtrue_fact 选择到 var 中并选择 fact_text。所以 sp 应该只将 fact_text 返回到我的 c# 程序,并且 sp 应该使用 idtrue_fact 来更新表。
  • 您不能在同一个查询中同时执行这两项操作,但 select into 不会返回结果集。您可能需要 2 个查询..

标签: mysql select select-into


【解决方案1】:

你有 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 ;

【讨论】:

  • 所以是全有还是全无?您不能正常选择一个并选择一个到 var 中?
  • 如您所见,我将两者都放入变量中,因此两者都使用或不使用都没关系
猜你喜欢
  • 2015-02-03
  • 1970-01-01
  • 2017-06-03
  • 2013-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多