java为什么不适合mysql,为什么“丢弃过程如果存在konami”不能在mysql中工作?

我写了一个mysql脚本,它工作正常:

use cloud_fight;

drop procedure if exists `konami`;

drop function if exists `rand_string`;

delimiter //

CREATE FUNCTION `rand_string`(n INT) RETURNS varchar(255)

BEGIN

DECLARE chars_str varchar(255) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789rew';

DECLARE return_str varchar(255) DEFAULT '';

DECLARE i INT DEFAULT 0;

while i < n do

SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*64 ),1));

SET i = i + 1;

END while;

RETURN return_str;

END //

delimiter $$

create procedure konami()

begin

declare q int default 1;

while q<=2 DO

set @N=rand_string(64);

insert into fight_user (user_guid , first_name , last_name , user_name , nick_name , gender , city , province , country , head_img_url , created_at , last_updated) values (@N, '' , '' , '' , rand_string(5) , '2' , 'bj' , 'bj' , 'cn' , '' , now() , now());

insert into fight_user_cake (fight_user_id , t_id , third_party_user_id , type , created_at , last_updated , status) select id , '2' , rand_string(20) , 'WECHAT_UNIONID' , now() , now() , 1 from fight_user where user_guid = @N;

insert into fight_user_cake (fight_user_id , t_id , third_party_user_id , type , created_at , last_updated , status) select id , '2' , rand_string(20) , 'MP_OPENID' , now() , now() , 1 from fight_user where user_guid = @N;

insert into fight_user_cake (fight_user_id , t_id , third_party_user_id , type , created_at , last_updated , status) select id , '2' , rand_string(20) , 'PA_OPENID' , now() , now() , 1 from fight_user where user_guid = @N;

set q=q+1;

end while;

end $$

call konami();

但是当我将命令“drop procedure if exists konami”移动到程序konami()的前面时,如下所示:

drop function if exists `rand_string`;

delimiter //

CREATE FUNCTION `rand_string`(n INT) RETURNS varchar(255)

BEGIN

DECLARE chars_str varchar(255) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789rew';

DECLARE return_str varchar(255) DEFAULT '';

DECLARE i INT DEFAULT 0;

while i < n do

SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*64 ),1));

SET i = i + 1;

END while;

RETURN return_str;

END //

drop procedure if exists `konami`;

delimiter $$

create procedure konami()

begin

declare q int default 1;

while q<=2 DO

set @N=rand_string(64);

insert into fight_user (user_guid , first_name , last_name , user_name , nick_name , gender , city , province , country , head_img_url , created_at , last_updated) values (@N, '' , '' , '' , rand_string(5) , '2' , 'bj' , 'bj' , 'cn' , '' , now() , now());

insert into fight_user_cake (fight_user_id , t_id , third_party_user_id , type , created_at , last_updated , status) select id , '2' , rand_string(20) , 'WECHAT_UNIONID' , now() , now() , 1 from fight_user where user_guid = @N;

insert into fight_user_cake (fight_user_id , t_id , third_party_user_id , type , created_at , last_updated , status) select id , '2' , rand_string(20) , 'MP_OPENID' , now() , now() , 1 from fight_user where user_guid = @N;

insert into fight_user_cake (fight_user_id , t_id , third_party_user_id , type , created_at , last_updated , status) select id , '2' , rand_string(20) , 'PA_OPENID' , now() , now() , 1 from fight_user where user_guid = @N;

set q=q+1;

end while;

end $$

call konami();

当我在mysql workbench 6.3中运行第二个脚本时 .

It report error : Error Code: 1304. PROCEDURE konami already exists

所以我的问题是当我将命令“drop procedure if exists konami”移动到程序konami()的前面时,为什么这个语句“如果存在konami的话程序”不工作?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值