Mysql函数-示例

好像有几年没写函数了,写了一个,记录一下,便于后续粘贴。

CREATE DEFINER=`loud`@`%` FUNCTION `change_uid`(tname TEXT) RETURNS int
    DETERMINISTIC
BEGIN
	#Routine body goes here...
	declare i int;
	   set i=59;
     while i>9 do
         update cloud_factory.device set company_uuid = CONCAT("42708008-78c0-4a1b-a6bd-dd65683c1c",i) where company_uuid = CONCAT("42708008-78c0-4a1b-a6bd-dd65683c1cc",i);
         set i=i-1;
     end while;

	RETURN i;
END