mysql 存储过程 模拟 php的explode 函数
来源:互联网 发布:mysql 存储过程 函数 编辑:程序博客网 时间:2024/04/30 15:35
今天 想模拟数据 为了 数据库分区用,想直接用mysql 实现 但是没有类似于php的explode 函数
gold.txt内容如下:
activity_find_back
add_jjc_chalenge_times
all_server_cup_egg
all_server_cup_encourange
all_server_cup_flower
all_server_cup_praise
all_server_cup_support
amulet_advance
amulet_growup_growup
amulet_growup_soul
amulet_growup_spirit
amulet_refresh_skill_book
equipment_lingyun
-- 获取有字符串 如上-面的例子 此方法会去掉'\n'
drop FUNCTION if exists `func_get_split_string`;
CREATE DEFINER=`pay_center`@`%` FUNCTION `func_get_split_string`( f_string varchar(1000),f_delimiter varchar(5),f_order int) RETURNS varchar(255) CHARSET utf8
DETERMINISTIC
BEGIN
declare result varchar(255) default '';
set result = reverse(substring_index(reverse(substring_index(f_string,f_delimiter,f_order)),f_delimiter,1));
return result;
END
=======================================================================
-- 根据'\n'为分割 统计有多少个
drop FUNCTION if exists `func_get_split_string_total`;
CREATE DEFINER=`pay_center`@`%` FUNCTION `func_get_split_string_total`(
f_string varchar(1000),f_delimiter varchar(5)
) RETURNS int(11)
DETERMINISTIC
BEGIN
-- Get the total number of given string.
return 1+(length(f_string) - length(replace(f_string,f_delimiter,'')));
END
=========================================================================
-- 执行
drop procedure if exists `sp_print_result`;
CREATE DEFINER=`pay_center`@`%` procedure `sp_print_result`(
IN rand_str varchar(10000),IN f_delimiter varchar(5)
)
set @rand_str = load_file('/tmp/gold.txt');
drop procedure if exists proce_range_partition_by_primary;create procedure proce_range_partition_by_primary(count int(11),rand_str varchar(1000),f_delimiter char(5))
begin
declare i int(11) default 0;
declare j int(11) default 0;
declare cnt int default 0;
//这一行是注视
set cnt = func_get_split_string_total(rand_str,f_delimiter);
select cnt;
-- 因为mysqll 里没有类似于 php的 获取一个数组的随即单元的函数,所以我存到了 内存表里
create temporary table tmp_print (reason varchar(30)character set utf8 default null)engine=memory default CHARSET=utf8;
while j < cnt
do
set j = j + 1;
insert into tmp_print(`reason`) values (func_get_split_string(rand_str,f_delimiter,j));
end while;
select * from tmp_print;
while i<= count do
set @i_s = i;
set @str='QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm1234567890';
set @roleid = bin(@i_s);
set @mod = mod(@i_s,2);
if @mod is null then
set @changecount = @i_s;
set @newcount = @i_s/2;
else
set @newcount = round(@i_s/2);
set @changecount = -i;
end if;
set i=i+1;
set @username = upper(md5(concat(@i_s,@str)));
-- 随机取出一个值
set @create_time = UNIX_TIMESTAMP()+i;
select @username,@i_s,@roleid,@changecount,@newcount,@reasons,@create_time;
insert into log_role_gold_change_bak set username = @username ,roleid = @roleid,changecount= @changecount, newcount = @newcount,reason = @reasons,create_time = @create_time;
set i=i+1;
end while;
end;
- mysql 存储过程 模拟 php的explode 函数
- PHP函数implode()与explode()的用法
- php的tips(explode函数)
- 【PHP】函数explode和split的区别
- php调用mysql存储过程和函数的方法
- php调用mysql存储过程和函数的方法
- PHP调用mysql存储过程和函数的方法
- php调用mysql存储过程和函数的方法
- php调用mysql存储过程和函数的方法
- php调用mysql存储过程和函数的方法
- php调用mysql存储过程和函数的方法
- php 函数 implode explode
- php explode() 函数
- PHP explode() 函数
- php explode() 函数
- PHP explode() 函数
- PHP explode() 函数
- PHP explode() 函数
- nefu 457(矩阵连乘)
- 实用级反主动防御rootkit设计思路
- LPC1768时钟配置
- android gridview setOnItemClickListener没有响应
- Android使用Zxing扫描二维码过程解决三星note1竖屏后花屏问题
- mysql 存储过程 模拟 php的explode 函数
- struts2表单验证里field-validator type值一共可以取哪些?都什么含义?
- Calendar和Date的常见用法
- break的fall through
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位
- leetcode: Add Binary
- 黄海波嫖娼却大受赞誉太荒唐
- 自行车新政策撒旦撒旦撒大恶趣味
- Cocos2D-X2.2.3学习笔记9(处理重力感应事件,移植到Android添加两次返回退出游戏效果)