create function transfer (account_source int, account_dest int, amount decimal)
returns BOOLEAN
BEGIN
DECLARE currency_source VARCHAR(20);
DECLARE currency_dest VARCHAR(20);
DECLARE current_balance DECIMAL;
DECLARE new_amount DECIMAL;
select balance into current_balance
from accounts
where number = account_source;
IF amount > current_balance THEN
return false;
END IF;
select currency into currency_source
from accounts
where number = account_source;
select currency into currency_dest
from accounts
where number = account_dest;
IF STRCMP(currency_source,'dollar') = 0 THEN
IF STRCMP(currency_dest,'euro') = 0 THEN
set new_amount := amount / 1.23;
ELSE IF STRCMP(currency_dest,'lbp') = 0 THEN
set new_amount := amount / 1500;
END IF;
end if;
IF STRCMP(currency_source,'euro') = 0 THEN
IF STRCMP(currency_dest,'dollar') = 0 THEN
set new_amount := amount * 1.23;
ELSE IF STRCMP(currency_dest,'lbp') = 0 THEN
set new_amount := (amount * 1.23) * 1500;
END IF;
end if;
IF STRCMP(currency_source,'lbp') = 0 THEN
IF STRCMP(currency_dest,'dollar') = 0 THEN
set new_amount := amount / 1500;
ELSE IF STRCMP(currency_dest,'euro') = 0 THEN
set new_amount := (amount / 1.23) / 1500;
END IF;
END IF;
update accounts
set balance = balance - amount
where number = account_source;
update accounts
set balance = balance + new_amount
where number = account_dest;
return true;
END;
尝试创建此功能会在第1行给出错误#1064,所以我无法猜出我所犯的实际错误在哪里。
我创建了'撤回'在它之前的函数,包含几乎相同的代码并且它起作用,传递函数和撤销函数之间的唯一区别是在开始时声明varchar(20)类型。
任何帮助将不胜感激......