feat: 基础库sql
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `changestr`(duty_territory VARCHAR(500), location int, str VARCHAR(500)) RETURNS varchar(500) CHARSET utf8mb4
|
||||
COMMENT '替换指定字符串'
|
||||
begin
|
||||
declare result varchar(500);
|
||||
declare str1 varchar(500);
|
||||
declare str2 varchar(500);
|
||||
declare num int;
|
||||
declare num1 int;
|
||||
declare num2 int;
|
||||
|
||||
set num = LENGTH(duty_territory) - LENGTH( REPLACE (duty_territory, ',', ''));
|
||||
set num1 = location-1;
|
||||
set num2 = 0-(num-location+1);
|
||||
|
||||
set str1 = substring_index(duty_territory,',',num1);
|
||||
set str2 = substring_index(duty_territory,',',num2);
|
||||
|
||||
if LENGTH(trim(str1))=0 && LENGTH(trim(str2))=0 then
|
||||
set result = str;
|
||||
|
||||
elseif LENGTH(trim(str1))=0 then
|
||||
set result = CONCAT(str,',',str2);
|
||||
|
||||
elseif LENGTH(trim(str2))=0 then
|
||||
set result = CONCAT(str1,',',str);
|
||||
|
||||
else
|
||||
set result = CONCAT(str1,',',str,',',str2);
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
end
|
||||
Reference in New Issue
Block a user