zoukankan      html  css  js  c++  java
  • Mysql 命令行下建立存储过程

    建立存储过程的sql如下:
    CREATE PROCEDURE  proc_variable ()
    BEGIN
    DECLARE dec_var_ VARCHAR(100);
    DECLARE rep_num INT;
    DECLARE dec_var CURSOR  for SELECT ID_  FROM ACT_RU_VARIABLE WHERE NAME_ = 'yjdqsj' GROUP BY EXECUTION_ID_ HAVING 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;
    如果把上面的语句直接执行的话,遇到第一个‘;'就结束了,然后剩下的都会报错。原因是默认mysql命令结束符是分号,需要修改结束符才可以执行。
    mysql(root@localhost:jjsworkflow)>delimiter //    #修改命令终止符为//(random)
    mysql(root@localhost:jjsworkflow)>CREATE PROCEDURE proc_variable ()
    -> BEGIN
    -> DECLARE dec_var_ VARCHAR(100);
    -> DECLARE rep_num INT;
    -> DECLARE dec_var CURSOR for SELECT ID_ FROM ACT_RU_VARIABLE WHERE NAME_ = 'yjdqsj' GROUP BY EXECUTION_ID_ HAVING 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;
    -> //    ##语句最后需要已上面声明的//结尾enter才能被执行
    即把//’''//之间的内容封装到一起执行。此修改是session级别,退出后即失效
    今日记一事,明日悟一理,积久而成学。
  • 相关阅读:
    12. Hamming Distance
    11. Sort Array By Parity
    10. Robot Return to Origin
    9. DI String Match
    8. Unique Email Addresses
    7. Unique Morse Code Words
    6. <Important> Flipping an Image
    5.<Important> Delete Node in a Linked List
    ubuntu20.04 combile opencv 3.2.0(fix some problem)
    git@github.com: Permission denied (publickey)问题解决
  • 原文地址:https://www.cnblogs.com/rockbes/p/3969786.html
Copyright © 2011-2022 走看看