由于语法错误,Mysql不允许我创建以下触发器,我想在我编写if语句的方式中,任何人都可以帮助解决这个问题吗?
DELIMITTER $$
CREATE TRIGGER gl_bal_upd_update AFTER UPDATE ON journal_line
FOR EACH ROW
BEGIN
DECLARE curr varchar(10);
DECLARE period varchar(10);
select period_name,currency
into period,curr
from journal_header jh
where jh.journal_header_id = NEW.journal_header_id;
INSERT IGNORE INTO general_ledger_balance (account_comb_id,period_name)values(NEW.account_comb_id,period);
UPDATE general_ledger_balance glb
SET glb.debit = IF(NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit > 0, NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit,0)(
,glb.credit = IF(NEW.credit + glb.credit - OLD.credit -NEW.debit - glb.debit + OLD.debit > 0, NEW.credit + glb.credit - OLD.credit - NEW.debit - glb.debit + OLD.debit,0)
,glb.currency = curr
WHERE glb.account_comb_id = NEW.account_comb_id
AND glb.period_name = period;
END $$
DELIMITER ;
答案 0 :(得分:0)
你的分隔符拼写错误,在一行的末尾随机加一个左括号。试试这个,它是通过语法错误得到的:
DELIMITER $$
CREATE TRIGGER gl_bal_upd_update AFTER UPDATE ON journal_line
FOR EACH ROW
BEGIN
DECLARE curr varchar(10);
DECLARE period varchar(10);
select period_name,currency
into period,curr
from journal_header jh
where jh.journal_header_id = NEW.journal_header_id;
INSERT IGNORE INTO general_ledger_balance (account_comb_id,period_name)values(NEW.account_comb_id,period);
UPDATE general_ledger_balance glb
SET glb.debit = IF(NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit > 0, NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit,0)
,glb.credit = IF(NEW.credit + glb.credit - OLD.credit -NEW.debit - glb.debit + OLD.debit > 0, NEW.credit + glb.credit - OLD.credit - NEW.debit - glb.debit + OLD.debit,0)
,glb.currency = curr
WHERE glb.account_comb_id = NEW.account_comb_id
AND glb.period_name = period;
END $$
DELIMITER ;