学习MySQL出现问题Not allowed to return a result set from a t

情况描述:

 

CREATE TRIGGER newcuster AFTER INSERT ON products

FOR EACH ROW SELECT ‘customer added‘;

出现错误Not allowed to return a result set from a trigger

学习MySQL出现问题Not allowed to return a result set from a t

 

查找原因是:MYSQL5以后,不允许触发器返回任何结果,因此使用into @变量名,将结果赋值到变量中,用select调用即可

修改为

CREATE TRIGGER newcustomer AFTER INSERT ON customers

FOR EACH ROW SELECT ‘customer added‘ INTO @add  

 

此时select @add

学习MySQL出现问题Not allowed to return a result set from a t

 

 发现触发器还没开始工作,因为现在还没往customers表中插入数据;

接下来在customers表插入一行数据:  

学习MySQL出现问题Not allowed to return a result set from a t

再运行SELECT @add;

可以看到触发器被触发了

学习MySQL出现问题Not allowed to return a result set from a t

 

学习MySQL出现问题Not allowed to return a result set from a t

上一篇:一条 SQL 引发的事故,同事直接被开除!!


下一篇:Mongodb