CREATE PROCEDURE addtitle_task_assignment()
begin
declare i int;
set i=0;
while i<100 do
insert into title_task_assignment (clientnum,paritionid,hold) values (0,i,0);
set i=i+1;
end while;
end;
DELIMITER $$
DROP PROCEDURE IF EXISTS updateDict $$
CREATE PROCEDURE updateDict()
begin
DECLARE no_more_dicts INT DEFAULT 0;
DECLARE prd_prodID INT DEFAULT 0;
DECLARE prd_keyword VARCHAR(255);
DECLARE prd_dictID INT DEFAULT 0;
DECLARE cur_dict CURSOR FOR SELECT id ,keyword FROM brand_dict where flag = 0;
#DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_dicts = 1; #加这句话有问题,循环进不去,求大神指点!!
OPEN cur_dict;
REPEAT
FETCH NEXT from cur_dict INTO prd_dictID,prd_keyword;
SELECT id into prd_prodID from selleck_product where instr(name,prd_keyword)>0 limit 1;
IF prd_prodID >0 then
update brand_dict set CATEGORYID = prd_prodID where id = prd_dictID;
END IF;
set prd_prodID = 0;
UNTIL no_more_dicts = 1
END REPEAT;
CLOSE cur_dict;
end $$
DELIMITER ;
推荐调试工具:Debugger For Mysql,试用版全功能14天免费
CREATE DEFINER=`root`@`localhost` PROCEDURE `p_test_prod_0726_01`()
BEGIN
DECLARE i int;
declare no_more_count int;
declare temp_username varchar(50);
declare temp_password varchar(50);
DECLARE cursor_user CURSOR FOR select username,password from manual_user;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_count=1;
SET i = 0;
SET no_more_count=0;
DROP TABLE IF EXISTS test_0726_01;
CREATE TABLE test_0726_01
(
id int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
u_name char(50),
u_pwd char(50),
date char(30)
)ENGINE=MEMORY DEFAULT CHARSET=utf8;
OPEN cursor_user;
REPEAT
-- Get order number
FETCH cursor_user INTO temp_username,temp_password;
INSERT INTO test_0726_01(u_name,u_pwd) VALUES(temp_username,temp_password);
UNTIL no_more_count END REPEAT;
CLOSE cursor_user;
#DROP TABLE test_0726_01;
END