注册 登录
编程论坛 MySQL论坛

求一个能计算加减乘除的 mysql自定义函数

ophelia 发布于 2013-08-28 10:04, 2622 次点击
求一个能计算加减乘除的 mysql自定义函数,
  用动态执行似乎一次只能执行一条,动态语句又不能放在函数中,但存储过程输出函数再放到其他语句中运用似乎又比较困难,所以请高人指点,是不是只有写自定义函数了,这个自定义函数该如何写呢?


我的需求是:

tb_a(id int,score_a varchar(100),score_b)

insert into tb_a
select 1, 100,200;

insert into tb_a
select 1,500,1000;
........


tb_b(id int ,score_formula varchar(100))

insert into tb_b
select 1 s/100*M;

insert into tb_b
select 1 m/10*s;

insert into tb_b
select 1 s/100*m;
。。。。。

update tb_a a,tb_b b
set a.score=  b.score_formula(结果要等于这个表达式就算后的结果,其中s 来自表tb_a.score_a,m 来自表tb_a.score_b)
where a.id=b.id

0 回复
1