本文介绍了mysql的两个字符串之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到MySQL中两个字符串之间的区别。说,如果输入了两个字符串nishant和nisha,则应输出'nt'。

I want to find the difference between two strings in MySQL. Say, if two strings like nishant and nisha are input, then 'nt' should be output.

推荐答案

set @string2 :="nishant";
Query OK, 0 rows affected (0.00 sec)

set @string1 := "nisha";
Query OK, 0 rows affected (0.00 sec)

select @string1, @string2;
+----------+----------+
| @string1 | @string2 |
+----------+----------+
| nisha    | nishant  |
+----------+----------+
1 row in set (0.00 sec)

select if(length(@string1)>length(@string2), replace(@string1, @string2,""), replace(@string2, @string1, "")) as "The Difference";
+----------------+
| The Difference |
+----------------+
| nt             |
+----------------+
1 row in set (0.00 sec)

这篇关于mysql的两个字符串之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 19:24