1.创建查询函数:(split_pid为函数名称)
create function split_pid(str varchar (1000),delimiter varchar(1)) returns varchar(200)
begin
declare cur_str varchar(200);
declare sub_len int;
declare sub_str varchar(200);
declare ret_str varchar(200);
declare loop_count int;
set cur_str = str;
set sub_len = -1;
set ret_str = '';
set loop_count = 0;
repeat
set cur_str = substring(cur_str,sub_len + 2);
set sub_str = substring_index(cur_str,delimiter,1);
set sub_len = length(sub_str);
if sub_len !=0 then
set ret_str = concat(ret_str,lpad(sub_str,6,'0'));
end if;
set loop_count = loop_count + 1;
until sub_len = 0
end repeat;
return ret_str;
end;
2.函数创建成功,写SQL语句
jyxm :表名,tt为函数排序后的简称
SELECT jy.id as id ,jy.bz as bz, split(jy.bz,'.') as tt
FROM jyxm jy
WHERE jy.tid='FE74159EF93E9AD1DD56F5BE82253C1B'
ORDER BY tt ASC
3.运行结果如下