从JavaScript函数indexOf和charAt转换MySQL函数POSITION和SUBSTR

时间:2017-10-17 13:39:18

标签: mysql stored-procedures

我想将JavaScript函数转换为MySQL函数。

JavaScript代码如下:

var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
var s = 0;

for( i = 1; i <= 13; i += 2 )
    s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
for( i = 0; i <= 14; i += 2 )
    s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));

所以,我已经&#34;翻译&#34;它来:

SET set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
SET set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
SET setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
SET setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
SET s=0;

SET v_counter = 0;
WHILE v_counter < 14
DO
    SET set1IndexOf = POSITION(SUBSTR(codFisc, v_counter+1, 1) IN set1);
    SET s = s + POSITION(SUBSTR(set2, set1IndexOf, 1) IN setpari) -1;
    SET v_counter=v_counter+2;
END WHILE;

SET v_counter = 0;
WHILE v_counter < 15
DO
    SET set1IndexOf = POSITION(SUBSTR(codFisc, v_counter+1, 1) IN set1);
    SET s = s + POSITION(SUBSTR(set2, set1IndexOf, 1) IN setdisp) -1;
    SET v_counter=v_counter+2;
END WHILE;

但MySQL函数返回错误的结果。

我知道charAtindexOf是从零开始的索引,而SUBSTRPOSITION是从一开始的索引。所以我增加了v_counter,但它仍然是错误的。 我无法看到这两个代码之间存在任何差异,但某处存在错误。

有人可以帮助我吗?

由于

0 个答案:

没有答案