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 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败