【发布时间】:2018-11-28 02:52:53
【问题描述】:
我们正在做一个关于小额银行的项目,我们需要在数据库级别计算利率。所以我们为此使用了程序和触发器。但是触发器需要每天立即执行才能执行以下给定程序。您能否提供创建该触发器的解决方案。提前致谢
DELIMITER //
create procedure addFDInterestToAccount(in account_number bigint(20))
BEGIN
declare interest float default 0;
declare account_type varchar(10);
declare rate float;
declare savings_account bigint(20);
start transaction;
select balance from fd_account where account_no = account_number into interest;
SELECT plan_id from fd_account where account_no = account_number into account_type;
SELECT saving_account_no from fd_account where account_no = account_number into savings_account;
select interest_rate from fd_plan where plan_id = account_type into rate;
set interest = interest*rate/1200;
insert into transaction (transaction_id, account_no, credit_debit, date_time, amount, type_, agent_id, is_fee) values (null, savings_account, 'debit', now(), interest, 'not_special', null, false);
update account set balance = balance + interest where account_no = savings_account;
commit;
END //
DELIMITER ;
call addFDInterestToAccount(90842311);
【问题讨论】:
-
是否必须只使用触发器...你为什么不考虑任务调度程序或 Windows 服务?
-
我正在使用 mariadb,我需要使用触发器。感谢@PrashantPimpale 的回复
-
@AhkamNaseek - 您可能需要在每个
SELECT末尾添加FOR UPDATE。