现在的位置: 首页 > 综合 > 正文

mysql存储过程中like用法

2013年09月17日 ⁄ 综合 ⁄ 共 663字 ⁄ 字号 评论关闭
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;

抱歉!评论已关闭.