如何将函数从MySQL转换为Firebird?
如何将此函数传递给firebird如何将函数从MySQL转换为Firebird?,mysql,firebird,firebird-3.0,Mysql,Firebird,Firebird 3.0,如何将此函数传递给firebird create function `candidat`(in_num decimal(10,2), in_group integer unsigned) returns integer unsigned deterministic language sql begin return case in_group when 1 then f
create function `candidat`(in_num decimal(10,2),
in_group integer unsigned)
returns integer unsigned
deterministic
language sql
begin
return case in_group when 1 then floor(in_num / 3.0 + 0.99)
when 2 then floor(in_num / 3.0 + 0.50)
else floor(in_num / 3.0) end;
end
有3种方法可以提取您需要的数据:
select
case when :in_group = 1 then floor(:in_num / 3.0 + 0.99)
when :in_group = 2 then floor(:in_num / 3.0 + 0.50)
else floor(:in_num / 3.0) end
from
RDB$DATABASE
OBS:RDB$数据库的只是一个表示例de result,而“:in_num”和“:in_group”是一个变量/参数,您可以使用一个表的列来更改它,或者只需输入所需的值
SET TERM ^ ;
CREATE OR ALTER procedure candidat (in_num decimal(10,2), in_group integer)
returns ( calculed_value integer )
as
begin
if (:in_group = 1) then
begin
calculed_value = floor(:in_num / 3.0 + 0.99);
end
else if (:in_group = 2) then
begin
calculed_value = floor(:in_num / 3.0 + 0.50);
end
else
begin
calculed_value = floor(:in_num / 3.0);
end
suspend;
end
^
SET TERM ; ^
您可以像这样使用它:
select
CALCULED_VALUE
from
candidat( 100, 2)
select
candidat(1,3)
from
<TABLE>
选择
候选人(1,3)
从…起
您可以创建Firebird 3 PSQL,它与MySQL函数几乎相同。主要区别在于创建语法:
create function candidat(in_num decimal(10,2),
in_group integer)
returns integer
as
begin
return case in_group when 1 then floor(in_num / 3.0 + 0.99)
when 2 then floor(in_num / 3.0 + 0.50)
else floor(in_num / 3.0) end;
end
由于Firebird没有无符号整数,因此需要使用普通(有符号)
整数。考虑到输入应该足够,否则考虑切换到<代码> BigIt .< /P> MySQL创建函数()查看FielBooDebug(创建函数)并在FielBoin手册中搜索其他语句/函数。如果你理解MySQL的create函数语法,并阅读firebird语法,那么你自己做起来应该很容易。请展示你的尝试,并解释你的坚持。除了函数头中的差异外,此函数应该几乎1对1进行转换。您错过了创建PSQL函数的Firebird 3选项。