同事的考试系统库最近查东西遇到个问题,答题选项如何判断ABCD等于DBCA,最初想通过查询条件like实现,实测出现诸多问题。查阅资料写了个函数比较字符串相等,不考虑字符串出现的位置。
CREATE FUNCTION bjstr(str VARCHAR (255),str1 VARCHAR (255))
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE i,n INT DEFAULT 0;
DECLARE jsstr VARCHAR (1);
SET i = LENGTH(str1);
IF (LENGTH (str) <> LENGTH (str1)) THEN
SET n = 0;
ELSE
WHILE i > 0 DO
SET jsstr = substring(str1,i,1);
SET str = INSERT(str,INSTR(str,jsstr),1,’’);
SET str1 = LEFT(str1,i-1);
SET i = i-1;
END WHILE;
IF (str = ‘’) THEN
SET n = 1;
ELSE
SET n = 0;
END IF;
END IF;
RETURN n;
END
参考资料:
https://www.cnblogs.com/wangb0402/p/6422762.html
https://www.cnblogs.com/hider/p/9071549.html
https://blog.csdn.net/ayqy42602/article/details/98770328
https://www.cnblogs.com/poloyy/p/12890763.html
https://bbs.csdn.net/topics/391020620