dtpf76658 2014-11-11 15:53
浏览 280

在触发器内使用select语句

So i have learned somhing abou triggers in mysql..While i as using selct statement inside the trigger it throws me error ..So after some research i have seen that using select statement and inserting into a variable can be done in trigger..So the code which i have used is

CREATE TRIGGER ins_sum AFTER UPDATE ON foo
FOR EACH ROW

declare some int;

select a from foo into some;


UPDATE foo SET a = 3 WHERE b = 1;

But it throws me error like Schema Creation Failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare some int'

Why is it like this ??..Any help would be apreciated..Thanx

  • 写回答

1条回答 默认 最新

  • donglinli2027 2014-11-11 16:04
    关注

    I presume that the UPDATE foo is not part of the trigger as it wouldn't work within a trigger on UPDATE foo.

    DELIMITER //
    CREATE TRIGGER ins_sum AFTER UPDATE ON foo
    FOR EACH ROW
    BEGIN
     declare some int;
    
     select NEW.a from foo into some;
    END
    //
    
    DELIMITER ;
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度