Create a stored procedure under Mysql command line

Source: Internet
Author: User
Tags mysql command line

the SQL that establishes the stored procedure is as follows:
CREATE PROCEDURE proc_variable () BEGIN DECLARE dec_var_ VARCHAR (+); DECLARE rep_num INT; DECLARE Dec_var CURSOR for SELECT id_ from act_ru_variable WHERE name_ = ' yjdqsj ' GROUP by Execution_id_ have Coun T (name_) >1; OPEN Dec_var; REPEAT FETCH Dec_var into Dec_var_; DELETE from act_ru_variable WHERE id_ = dec_var_; UNTIL rep_num END REPEAT; CLOSE Dec_var; end;
If the above statement is executed directly, it encounters the first '; ' It's over, and then all the rest will get an error. The reason is that the default MySQL command terminator is a semicolon and requires a modified terminator to execute.
MySQL ([email protected]: Jjsworkflow) >delimiter//#修改命令终止符为//(random) MySQL ([email protected]: jjsworkflow) >create PROCEDURE proc_variable () BEGIN DECLARE dec_var_ VARCHAR (+); - DECLARE rep_num INT; - DECLARE Dec_var CURSOR for SELECT id_ from act_ru_variable WHERE name_ = ' yjdqsj ' GROUP by Execution_id_ have COUNT (name_) >1; -- OPEN Dec_var; REPEAT -- FETCH dec_var into Dec_var_; -- DELETE from act_ru_variable WHERE id_ = dec_var_; - UNTIL rep_num END REPEAT; -- CLOSE Dec_var; - end; / /# #语句最后需要已上面声明的//End Enter to be executed
that is, the contents of//'//are encapsulated together to execute. This modification is session level and expires after exiting

Create a stored procedure under Mysql command line

Related Article

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.