您好,欢迎来到钮旅网。
搜索
您的当前位置:首页SQL,存储过程,循环

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 ()

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- niushuan.com 版权所有 赣ICP备2024042780号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务