duanrongpai9556 2013-05-09 11:40
浏览 45
已采纳

当我在mySql中创建事件时指定第二个列名时,为什么选择失败?

When creating an event, why do I get Undeclared variable: voteType when I add a second column to the select sql? Is it not possible to specify a second column in the sql statement? What's the right way to do this?

BEGIN

DECLARE c VARCHAR(2);
DECLARE vElm INT(10);
DECLARE vType TINYINT(1);

select distinct(country) into c from votes;

select votedElm into vElm, voteType into vType from votes where country = c;

END
  • 写回答

1条回答 默认 最新

  • duanbigan7765 2013-05-09 11:44
    关注

    That's because the INTO syntax in your second case is expecting a variable array as the destination. It's seeing vElm, voteType as the array of variables, but since voteType hasn't been declared as one (because it's really one of your columns), you get an exception. Try it this way instead:

    select <columns> into <variables> from ...
    

    In your case:

    select votedElm, voteType into vElm, vType from votes where country = c;
    

    There are examples in the MySQL reference for INTO.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制