- CREATE PROCEDURE `proc_init_tagsData`()
- begin
- DECLARE v_keyword varchar(30);
- DECLARE v_tag_id int default -1;
- DECLARE v_done int;
- DECLARE v_count int default 0;
- -- 定义游标
- DECLARE rs_cursor CURSOR FOR select keyword from t_keyword where s_flag=1 order by id limit 15;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done=1;
- open rs_cursor;
- cursor_loop:loop
- FETCH rs_cursor into v_keyword; -- 取数据
- if(v_count<15) then
- insert into t_tag (name)values(v_keyword);
- set v_tag_id = LAST_INSERT_ID();
- -- 关键是like CONCAT(‘%‘,v_keyword,‘%‘); 这里的用法
- insert into tbl_sm_tag (tag_id,soft_id) select v_tag_id,id from sm where soft_name like CONCAT(‘%‘,v_keyword,‘%‘);
- end if;
- set v_count = v_count + 1;
- if v_done=1 then
- leave cursor_loop;
- end if;
- end loop cursor_loop;
- close rs_cursor;
时间: 2024-10-20 21:03:45