gpt4 book ai didi

mysql - 如何创建一个触发器,在使用 SQL 插入之前将空字符串设置为 null?

转载 作者:行者123 更新时间:2023-11-29 09:13:54 25 4
gpt4 key购买 nike

我正在使用 phpmyadmin,但我不知道如何让它在导入数据时自动将空字符串设置为 null,因此我尝试编写一个触发器来执行此操作。

我的触发器最终必须包含比这更多的字段,但这是我的测试运行触发器,它不起作用:

create trigger test1
before insert
on hvi
for each row
begin
if new.`Amt` = ' ' then
set new.`Amt` = null
end if;
end;

我收到此错误:

MySQL said: Documentation # 1064 - 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 'end if' at line 8

我做错了什么?

最佳答案

if new.`Amt` = ' ' then
set new.`Amt` = null ;
end if;

关于mysql - 如何创建一个触发器,在使用 SQL 插入之前将空字符串设置为 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4737687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com