当前位置:Gxlcms > mysql > mysql存储过程实例分享_MySQL

mysql存储过程实例分享_MySQL

时间:2021-07-01 10:21:17 帮助过:10人阅读

一个mysql存储过程实例代码。

mysql存储过程

delimiter $DROP FUNCTION IF EXISTS `fun_convert`$CREATE DEFINER=`root`@`%` FUNCTION `fun_convert`(para varchar(255))RETURNS varchar(255) CHARSET gbkBEGINdeclare result varchar(255) default '';declare cnt int default 0;declare i int default 0;declare id BIGINT default 0;set cnt = length(para) - length(replace(para,',',''))-1;WHILE i < cnt DOselect c.id into id from company c where c.code = SUBSTRING(para,i*3+2,2);set result = CONCAT(result, ",",id);set i = i+1;end WHILE;set result = CONCAT(result, ",");RETURN result;END$ ---www.jbxue.comdelimiter ;update users u set u.company = fun_convert(u.COMPANY);

人气教程排行