当前位置:   article > 正文

mysql中字符串1.1.1/1.2.1/1.20.2/1.29.5/3.1/4.0排序问题_mysql 实现 1.1.1 排序

mysql 实现 1.1.1 排序

mysql中字符串1.1.1/1.2.1/1.20.2/1.29.5/3.1/4.0排序问题

 

 

  1. # create by john tang
  2. # date 2019-07-24
  3. # this fun is for serial_numbe as "1.1.1.1,2.0,1.32.10" to order by
  4. # use it likes select * from test ORDER BY split_serial_number(serial_number,'.') ASC
  5. create function split_serial_number(str varchar (1000),delimiter varchar(1)) returns varchar(200)
  6. begin
  7. declare cur_str varchar(200);
  8. declare sub_len int;
  9. declare sub_str varchar(200);
  10. declare ret_str varchar(200);
  11. declare loop_count int;
  12. set cur_str = str;
  13. set sub_len = -1;
  14. set ret_str = '';
  15. set loop_count = 0;
  16. repeat
  17. set cur_str = substring(cur_str,sub_len + 2);
  18. set sub_str = substring_index(cur_str,delimiter,1);
  19. set sub_len = length(sub_str);
  20. if sub_len !=0 then
  21. set ret_str = concat(ret_str,lpad(sub_str,6,'0'));
  22. end if;
  23. set loop_count = loop_count + 1;
  24. until sub_len = 0
  25. end repeat;
  26. return ret_str;
  27. end;

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号