SQL,存储过程,循环

------------------------------------------------------------------------------------

sql自定义函数

DELIMITER //
CREATE FUNCTION calculate(price decimal(19,3),taxType varchar(20), taxRate decimal(19,3)) 
RETURNS decimal(19,3)
begin
   DECLARE a decimal(19,3) DEFAULT 0;
   declare excludeInPrice varchar(20) default "excludeInPrice";
   declare includeInPrice varchar(20) default "includeInPrice";
   if excludeInPrice=taxType
      THEN SET a = (price/(1+taxRate))*taxRate;
   end if;
   if includeInPrice=taxType
      THEN SET a = price * taxRate;
   end if;
   RETURN a;
END//
DELIMITER ;

update e_retail_return_product r join e_product p 
set r.tax=calculate(r.amount ,p.in_tax_type ,p.in_tax_rate),r.tax_type =p.in_tax_type,r.tax_rate =p.in_tax_rate  
where p.id = r.product_id;

DROP FUNCTION calculate;

------------------------------------------------------------------------------------

创建存储过程

create procedure insert_mhp_trans_info_his3000000a ()

define i int;

let i = 2000000;

while i < 4000000

INSERT INTO mhp_trans_info_his (trans_jnlno)

VALUES (i);

let i = i + 1;

end while;

end procedure;

执行

call insert_mhp_trans_info_his3000000a()

删除

drop procedure insert_mhp_trans_info_his3000000a ()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值