Mysql存储过程创建获得2014年错误

时间:2014-02-10 09:05:57

标签: php mysql stored-procedures

尝试创建我的第一个存储过程,我已经进行了广泛的研究,并且找不到通过phpMyAdmin输入代码的方法,所以下载了MYSQL Workbench 6.0并以这种方式放置了我的脚本 - 但它抛出了2014 error (Commands out of sync, you cannot run this command now)。但是我注意到Workbench似乎创建了两行 - 第一行表示运行,第二行表示错误。

例程是更新三个表并在签发合同时插入另一个表。合同由捆绑组成,它们又包含与另一个表中的特定问题相关的项目。

这是我的代码还是应该在最后添加一些清除命令,如果是这样,应该是什么?过程输入是合同ID,用户ID及其IP地址(用于记录)。

在PHP中,最终,使用CALL我将如何清除结果,因为我一直看到Stackoverflow 2014在第二次调用失败时回答?另外我怎样才能通过phpMyAdmin将它放到ubuntu服务器上,或者如果用putty将sql脚本ftp放到哪里?

DELIMITER //

DROP PROCEDURE IF EXISTS ContrctAwardStatusLog;

CREATE PROCEDURE ContrctAwardStatusLog( IN c_Id INT(8), IN u_Id INT(11), IN u_Ip varchar(20) )
BEGIN
  Block1: BEGIN
    DECLARE done INT DEFAULT 0;
    DECLARE b_id INT DEFAULT 0;
    DECLARE citm_id INT DEFAULT 0;
    DECLARE r_id INT DEFAULT 0;
    DECLARE c_1 CURSOR FOR SELECT bundle_id FROM bundles WHERE  contract_id = c_Id;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

    OPEN c_1;
    REPEAT
      FETCH c_1 INTO b_id ;

      Block2: BEGIN
        DECLARE done2 INT DEFAULT 0;
        DECLARE c_2 CURSOR FOR SELECT contitem_id, issue_id FROM c_items WHERE bundle_id= b_id;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = 1;

        OPEN c_2;
        REPEAT
          FETCH c_2 INTO citm_id r_id;
          INSERT INTO track_status (rowid, WStatusBy, WStatus, WStatusWhen) VALUES(r_id, u_Id, 13,NOW());
          UPDATE h_issues SET WStatus='13' WHERE RowID = r_id;
          UPDATE c_items SET act_state='13' WHERE contitem_id=citm_id;

          UNTIL done2
        END REPEAT;
        CLOSE c_2;
      END Block2;

      UPDATE bundles SET bundle_stat = '13' WHERE bundle_id = b_id;
      UNTIL done
    END REPEAT;

    CLOSE c_1;
  END Block1;

END //

DELIMITER ;

1 个答案:

答案 0 :(得分:0)

我终于对此进行了整理。

我需要在DELIMITER设置之前放置DROP ..if,并且在OPEN c_2之后FETCH中存在语法错误。它缺少一个逗号分隔符。

DROP PROCEDURE IF EXISTS ContrctAwardStatusLog;

DELIMITER //

CREATE PROCEDURE ContrctAwardStatusLog( IN c_Id INT(8), IN u_Id INT(11), IN u_Ip varchar(20) )
BEGIN
  Block1: BEGIN
    DECLARE done INT DEFAULT 0;
    DECLARE b_id INT DEFAULT 0;
    DECLARE citm_id INT DEFAULT 0;
    DECLARE r_id INT DEFAULT 0;
    DECLARE c_1 CURSOR FOR SELECT bundle_id FROM bundles WHERE  contract_id = c_Id;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

    OPEN c_1;
    REPEAT
      FETCH c_1 INTO b_id ;

      Block2: BEGIN
        DECLARE done2 INT DEFAULT 0;
        DECLARE c_2 CURSOR FOR SELECT contitem_id, issue_id FROM c_items WHERE bundle_id= b_id;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = 1;

        OPEN c_2;
        REPEAT
          FETCH c_2 INTO citm_id, r_id;
          INSERT INTO track_status (rowid, WStatusBy, WStatus, WStatusWhen) VALUES(r_id, u_Id, 13,NOW());
          UPDATE h_issues SET WStatus='13' WHERE RowID = r_id;
          UPDATE c_items SET act_state='13' WHERE contitem_id=citm_id;

          UNTIL done2
        END REPEAT;
        CLOSE c_2;
      END Block2;

      UPDATE bundles SET bundle_stat = '13' WHERE bundle_id = b_id;
      UNTIL done
    END REPEAT;

    CLOSE c_1;
  END Block1;

END //

DELIMITER ;