Get the App
SLTechnology News&Howtos  ›  Database  › 

Example Analysis of Mysql obtaining the largest same substring in two Strings

Shulou Source: shulou.com Published: 2022-05-31 14:04:47 09月25日 Update

Today, I will talk to you about the example analysis of Mysql getting the largest of the same substrings of the two strings. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Length: returns the number of bytes occupied by the string, which is the length of the calculated field. Under utf8 coding, a Chinese character is counted as three characters, and a number or letter is counted as a character. Under other codes, a Chinese character is counted as two characters, and a number or letter as a character.

Char_length: returns the number of characters occupied by a string, regardless of Chinese characters or numbers or letters.

DELIMITER $$

CREATE DEFINER= `testuser` @ `% `getMaxSubStrP` (`inParam1` varchar, `inParam2` varchar, out `resultStr` VARCHAR, out `resultLen`)

BEGIN

DECLARE longStr VARCHAR (255)

DECLARE shortStr VARCHAR (255)

DECLARE tempStr VARCHAR (255)

DECLARE tempResult VARCHAR (255) DEFAULT ""

DECLARE strLength2 INT DEFAULT 0

DECLARE strLength3 INT DEFAULT 0

DECLARE minStrLength INT DEFAULT 0

DECLARE startIndex INT DEFAULT 0

DECLARE endIndex INT DEFAULT 1

DECLARE cmpInt INT DEFAULT 0

SELECT CHAR_LENGTH (inParam1), CHAR_LENGTH (inParam2) INTO strLength2,strLength3 FROM DUAL

SET minStrLength = strLength2

IF minStrLength > strLength3 THEN

SET minStrLength=strLength3

SET longStr = inParam1

SET shortStr = inParam2

ELSE

SET longStr=inParam2

SET shortStr=inParam1

End if

-- select minStrLength,longStr,shortStr

WHILE startIndex < minStrLength

DO

SET endIndex = startIndex + 1

WHILE endIndex0) AND (CHAR_LENGTH (tempResult)

Tags: Characters strings two content letters numbers Chinese characters maximum same examples analysis coding three fields bytes more knowledge articles industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB Microsoft macOS Shulou Tech Info