mysql 存储过程

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值