Like usage in MySQL stored procedure

Source: Internet
Author: User

  1. CREATE PROCEDURE ' Proc_init_tagsdata ' ()
  2. Begin
  3. DECLARE v_keyword varchar (30);
  4. DECLARE v_tag_id int default-1;
  5. DECLARE v_done int;
  6. DECLARE v_count int default 0;
  7. --Defining cursors
  8. DECLARE rs_cursor cursor for select keyword from t_keyword where s_flag=1 ORDER by ID limit  15;
  9. DECLARE CONTINUE HANDLER for not FOUND SET v_done=1;
  10. Open rs_cursor;
  11. Cursor_loop:loop
  12. FETCH rs_cursor into V_keyword; --Fetch data
  13. if (v_count<15) Then
  14. INSERT INTO t_tag (name)values (V_keyword);
  15. Set v_tag_id = last_insert_id ();
  16. --The key is like CONCAT ('% ', v_keyword, '% ');
  17. INSERT INTO tbl_sm_tag (tag_id,soft_id) select V_tag_id,id from sm where soft_name like CONCAT (  '% ', v_keyword,'% ');
  18. End If;
  19. Set V_count = V_count + 1;
  20. If v_done=1 Then
  21. Leave Cursor_loop;
  22. End If;
  23. End Loop Cursor_loop;
  24. Close rs_cursor;

Like usage in MySQL stored procedure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.