Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report