strcmp函数是string compare(字符串比较)的缩写,用于比较两个字符串并根据比较结果返回整数。基本形式为strcmp(str1,str2),若str1=str2,则返回零;若str1<str2,则返回负数;若str1>str2,则返回正数。
达梦数据库没有这个函数,只能曲线救国,把string转成ASCII码在比较
代码如下:
CREATE OR REPLACE FUNCTION DM_FUNC_COMPAIR (para1 IN VARCHAR,para2 IN VARCHAR ) RETURN VARCHAR ASdeclarepara3 int;para4 int; BEGINIFpara1 == para2THENRETURN 0;ELSEIF length(para1) < length(para2) THENpara3 = length(para1);ELSEIF length(para1) > length(para2) THENpara3 = length(para2);ELSEIF length(para1) == length(para2) THENpara3 = length(para1);END IF;FOR i IN 1..para3LOOPIF ascii(substr(para1, i, 1)) < ascii(substr(para2, i, 1)) THENpara4 = -1;RETURN -1;ELSEIF ascii(substr(para1, i, 1)) > ascii(substr(para2, i, 1)) THENpara4 = 1;RETURN 1;ELSEIF ascii(substr(para1, i, 1)) == ascii(substr(para2, i, 1)) THENpara4 = 0;END IF;END LOOP;IFpara4 == 0 and para3 == length(para1) THENRETURN -1;ELSERETURN 1;END IF;RETURN para4; END;