• mysql遍历字符串,按ASCII码拼接返回数字


    对于按照字符排序,对于排序的结果值需要运算的,可能直接order by (xxx + 0)的形式可能行不通,于是调用函数 to_number(xxx),可以对于返回数字进行排序

    DELIMITER $$
    
    USE `maventest`$$
    
    DROP FUNCTION IF EXISTS `to_number`$$
    
    CREATE DEFINER=`root`@`localhost` FUNCTION `to_number`(NAME VARCHAR(255) CHARSET gbk) RETURNS VARCHAR(4000) CHARSET gbk
    BEGIN
        DECLARE mycode INT;
        DECLARE tmp_lcode VARCHAR(2) CHARSET gbk;
        DECLARE lcode INT;
        DECLARE mypy VARCHAR(4000) CHARSET gbk DEFAULT '';
        DECLARE lp INT;
        SET mycode = 0;
        SET lp = 1;
        SET NAME = HEX(NAME);
        WHILE lp < LENGTH(NAME) DO
            SET tmp_lcode = SUBSTRING(NAME, lp, 2);
            SET lcode = CAST(ASCII(UNHEX(tmp_lcode)) AS UNSIGNED);
            IF lcode > 128 THEN
                SET lp = lp + 4;
            ELSE
                SET lp = lp + 2;
            END IF;
            SET mypy = CONCAT(mypy,lcode);
        END WHILE;
        RETURN LOWER(mypy);
    END$$
    
    DELIMITER ;


  • 相关阅读:
    禁止网页后退
    C# 数组排序
    SQL求往年的工资和
    手机的隐秘功能
    C#中的String类
    C#修饰符
    Application,Session,Cookie,ViewState和Cache区别
    css margin和padding的区别
    php常见的js正则表达式
    js 正则表达式基础篇
  • 原文地址:https://www.cnblogs.com/dulinan/p/12033096.html
Copyright © 2020-2023  润新知