我尝试创建一个与 Oracle 中的函数具有相同功能的TRANSLATE
函数,我在 Oracle 中创建了函数并且效果很好,但是当我尝试将此代码重写为 Firebird 时出现问题。我收到“不支持表达式评估”的错误。为什么?
CREATE FUNCTION TRANSLATEE
(text varchar(10000),
toReplace varchar(10000),
replacePattern varchar(10000)
)
RETURNs VARCHAR(100)
aS
declare variable cut varchar(100);
declare variable i integer;
declare variable position1 varchar(100);
declare variable resultat varchar(100);
declare variable letter varchar(100);
declare variable lenght integer;
BEGIN
i = 1;
resultat ='';
lenght = char_length(:text);
while(i<lenght) do
begin
cut = substring(:text from i for 1);
position1 = position(:toReplace , cut);
if (position(:toReplace , cut) >0) then
begin
letter = substring(:replacePattern from position1 for 1);
resultat = resultat||''||letter;
end
else
begin
resultat = resultat ||''|| cut;
end
i = i+1;
end
RETURN resultat;
END;