mysql存储过程语法错误

时间:2009-04-15 19:32:14

标签: mysql stored-procedures

好的,这只是我写的第二个存储过程。我想你会得到这个想法,我正试图关闭一个信用额度,以及所有的发票,收费,票据等。但是我收到语法错误。 目标是CALL close_account_proc(398985994)

DELIMITER $$

CREATE
    PROCEDURE `cc`.`close_account_proc`(cid INT)
    @uid_usr := uid_usr FROM credit_acc WHERE type_acc = 'init' AND credit_used_acc = cid;
    UPDATE credit_acc SET status_acc = 'closed', void_date_acc = NOW() WHERE credit_used_acc = cid;
    UPDATE payment_acc SET status_acc = 'voided', void_date_acc = NOW()  WHERE creditid_acc = cid;
    UPDATE sbal_sbl SET status_sbl = 'voided', void_date_sbl = NOW()  WHERE credit_used_acc = cid;
    INSERT INTO notes_not SET uid_usr = @uid_usr, initials_not = 'SYS',status_not = 'complete', date_not = NOW(), text_not = 'Closed credit line '.cid;
    UPDATE invoices_inv SET status_inv = 'voided', void_date_inv = NOW()  WHERE credit_used_acc = cid;
    BEGIN
    END$$

DELIMITER ;

所以,总之,我得到这个错误: 您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在credit_acc附近的'@uid_usr:= uid_usr附近使用正确的语法,其中type_acc ='init'和credit_used_acc'在第5行。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

DELIMITER $$

CREATE PROCEDURE `cc`.`close_account_proc`(cid INT)
BEGIN
    /* Check that it's what you wanted */
    SELECT  uid_usr
    INTO    @uid_usr
    FROM    credit_acc
    WHERE   type_acc = 'init'
            AND credit_used_acc = cid;

    UPDATE credit_acc SET status_acc = 'closed', void_date_acc = NOW() WHERE credit_used_acc = cid;
    UPDATE payment_acc SET status_acc = 'voided', void_date_acc = NOW()  WHERE creditid_acc = cid;
    UPDATE sbal_sbl SET status_sbl = 'voided', void_date_sbl = NOW()  WHERE credit_used_acc = cid;

    /* Check that it's what you wanted */

    INSERT
    INTO    notes_not (uid_usr, initials_not, status_not, date_not, text_not)
    VALUES  (@uid_usr, 'SYS', 'complete', NOW(), CONCAT('Closed credit line ', cid));

    UPDATE invoices_inv SET status_inv = 'voided', void_date_inv = NOW()  WHERE credit_used_acc = cid;
END
$$

DELIMITER ;

答案 1 :(得分:0)

嗯,我不是存储过程的专家,但不是。

CREATE PROCEDURE `cc`.`close_account_proc`(cid INT)
    BEGIN
        // your stuff
    END$$