antony--异域空间
性格左右命运,气度影响格局!
DELIMITER $$

 

DROP PROCEDURE IF EXISTS `SPLIT_SUB_STR0`$$

CREATE DEFINER=`admin`@`%` PROCEDURE `SPLIT_SUB_STR0`(INOUT str VARCHAR(1000) , split0 VARCHAR(1) ,OUT split VARCHAR(20))
BEGIN
 DECLARE  c INT;
 SET c=0;
SET c = LENGTH(SUBSTRING_INDEX(str,split0,1));
SET split = SUBSTRING(str, 1, c);
SET str = SUBSTRING(str, c + 2 );
    END$$

DELIMITER ;


DELIMITER $$

 

DROP PROCEDURE IF EXISTS `test`$$

CREATE DEFINER=`admin`@`%` PROCEDURE `test`()
BEGIN
 DECLARE  c INT;
#目标字符串
SET @a = '1,,3,4,5,6,12';
# 分隔符
SET @c = ',';
# 存储风格后的字符串
SET @b = '';
REPEAT
    # 调用上面的存储过程
    CALL SPLIT_SUB_STR0(@a, ',', @c);
    #将取得的字符串拼接,测试用
    
     SET @b =CAST(@b AS SIGNED INTEGER) + CAST(@c AS SIGNED INTEGER) ;
#当目标字符串为空时,停止循环
UNTIL @a = ''
END REPEAT;
# 查看结果
SELECT @a, @c, @b;
 
 
    END$$

DELIMITER ;
posted on 2010-12-24 18:12  antony.net  阅读(262)  评论(0编辑  收藏  举报