将 Levenshtein 距离函数添加到 MySQL
要将 Levenshtein 距离函数合并到 MySQL,请导航到 MySQL Workbench 并执行以下语句:
CREATE FUNCTION levenshtein(s1 VARCHAR(255), s2 VARCHAR(255)) RETURNS INT DETERMINISTIC BEGIN DECLARE len1 INT DEFAULT LENGTH(s1); DECLARE len2 INT DEFAULT LENGTH(s2); DECLARE i, j, cost, temp INT DEFAULT 0; DECLARE c1, c2 CHAR(1); IF len1 = 0 THEN RETURN len2; ELSEIF len2 = 0 THEN RETURN len1; END IF; SET cost = ARRAY(len1 + 1, len2 + 1); FOR i = 1 TO len1 DO SET cost[i][0] = i; END FOR; FOR j = 1 TO len2 DO SET cost[0][j] = j; END FOR; FOR i = 1 TO len1 DO c1 = SUBSTR(s1, i, 1); FOR j = 1 TO len2 DO c2 = SUBSTR(s2, j, 1); IF c1 = c2 THEN SET temp = 0; ELSE SET temp = 1; END IF; SET cost[i][j] = LEAST(cost[i - 1][j] + 1, cost[i][j - 1] + 1, cost[i - 1][j - 1] + temp); END FOR; END FOR; RETURN cost[len1][len2]; END;
这将在您的MySQL 实例。
PHP 中的示例用法
要在 PHP 中使用该函数,请连接到 MySQL 数据库并使用 levenshtein() 函数执行查询:
<?php $servername = "localhost"; $database = "test"; $username = "root"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password, $database); // Execute query $result = $conn->query("SELECT levenshtein('abcde', 'abced')"); // Get result $row = $result->fetch_assoc(); // Print result echo $row['levenshtein(s1, s2)']; ?>
在本例中,查询返回 2,表示“abcde”和“abcde”之间的编辑距离“abced”是 2。
以上是如何在MySQL中添加和使用编辑距离函数?的详细内容。更多信息请关注PHP中文网其他相关文章!

todropaviewInmySQL,使用“ dropviewifexistsview_name;” andTomodifyAview,使用“ createOrreplaceViewViewViewview_nameAsSelect ...”。whendroppingaview,asew dectivectenciesanduse和showcreateateviewViewview_name;“ tounderStanditSsstructure.whenModifying

mySqlViewScaneFectectialized unizedesignpatternslikeadapter,Decorator,Factory,andObserver.1)adapterPatternadaptSdataForomDifferentTablesIntoAunifiendView.2)decoratorPatternenhancateDataWithCalcalcualdCalcalculenfields.3)fieldfields.3)

查看InMysqlareBeneForsImplifyingComplexqueries,增强安全性,确保dataConsistency,andOptimizingPerformance.1)他们simimplifycomplexqueriesbleiesbyEncapsbyEnculatingThemintoreusableviews.2)viewsEnenenhancesecuritybyControllityByControllingDataAcces.3)

toCreateAsimpleViewInmySQL,USEthecReateaTeviewStatement.1)defitEtheetEtheTeViewWithCreatEaTeviewView_nameas.2)指定usethectstatementTorivedesireddata.3)usethectStatementTorivedesireddata.3)usetheviewlikeatlikeatlikeatlikeatlikeatlikeatable.views.viewssimplplifefifydataaccessandenenanceberity but consisterfort,butconserfort,consoncontorfinft

1)foralocaluser:createUser'localuser'@'@'localhost'Indidendify'securepassword'; 2)foraremoteuser:creationuser's creationuser'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Rocaluser'@'localhost'Indidendify'seceledify'Securepassword'; 2)

mysqlviewshavelimitations:1)他们不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinSorsubqueries.2)他们canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

porthusermanagementInmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)复杂的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Dreamweaver CS6
视觉化网页开发工具