mysql - 如何使用 SELECT 和 IF 条件在 mysql 中触发?
问题描述
如果为NULL,我正在尝试创建一个触发器来更改taille 列的值。
我知道大一新生的另一个语法错误,这是一件可笑的事情。但是,这个水平比我高太多了。
你可以从她那里开始阅读代码:
#1064 - Erreur de syntaxe près de 'select i.id from categorie cat,souscategorie scat,item i,panier p where p.idite=' à la ligne 3。
delimiter /
create trigger voiddresstaille before insert on panier for each row
begin
if new.idite=(select i.id from categorie cat,souscategorie scat,item i,panier p where p.idite=i.id and i.idscat=scat.id and scat.idcat=cat.id and cat.nom='Vêtements & Chaussures') then
if new.taille='' || new.taille=NULL then
new.taille='M';
end if;
end if;
end /
如果您不知道答案,请投票支持我。谢谢你。
解决方案
你的语法是错误的。
我将您的查询更改为正确的内部连接
您只能从您的选择中获得一个 i.id,否则这会导致错误
DROP TRIGGER IF EXISTS voiddresstaille ;
delimiter //
create trigger voiddresstaille before insert on panier for each row
begin
if new.idite = (select i.id
from categorie cat
INNER JOIN souscategorie scat ON scat.idcat=cat.id
INNER JOIN item i ON i.idscat=scat.id
INNER JOIN panier p ON p.idite=i.id
where cat.nom='Vêtements & Chaussures') then
if new.taille='' OR new.taille IS NULL then
SET new.taille='M';
end if;
end if;
end //
DELIMITER ;
推荐阅读
- java - 在片段中显示 RecyclerView
- node.js - 如何从 Node JS 客户端的响应中读取和保存 pdf 文件
- python - 如何在 scikit learn 中为多变量回归绘制最佳拟合平面?
- java - 如何在java中读取小数形式的jsonobjects?
- java - 迭代时移除元素。removeIf 导致 ConcurrentModificationException
- r - 如何在 R Markdown 的表格正文中显示希腊字母?
- python - 使用 BeautifulSoup4 设置 XML 属性值
- reporting-services - 是否可以从 SSRS 报告数据中找到所有匹配的字符串?
- unity3d - 在 Unity 2D 中移动时从对撞机上落下的 2d 刚体
- entity-framework - Linq 获取每个 Make into DTO 的模型列表