【发布时间】:2020-02-09 16:26:15
【问题描述】:
我学过 Oracle SQL 中的触发器,但对 MySQL 不太熟悉。我试图将触发命令从 Oracle 转换为 MySQL。首先,我找不到when 语句,而是找到了if else。这是我写的:
create trigger overdraft
after update on account
for each row
begin
if account.balance < 0 then
insert into borrower(select customer_name, account_number from depositor where new.account_number=depositor.account_number);
insert into loan(select new.account_number, new.branch_name, new.balance);
update account set balance = 0 where account.account_number = new.account_number;
end if;
end;
但是我得到三个语法错误,首先是在左括号的第一个插入语句的末尾,说“语句不完整,期待:','”。另外两个在每个ends 上说“结束在这个位置无效:期待开始,EOF,......”。我的代码有什么问题?我很难弄清楚。
【问题讨论】:
-
在 mysql 中,您无法操作触发触发器的表 - 在本例中为帐户。您可以调整新的。前触发器中的值。你需要重新考虑你的方法