mysql存储过程语法错误

mysql存储过程语法错误

本文介绍了mysql存储过程语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这只是我编写的第二个存储过程.我想您会明白的,我正在尝试关闭一个信用额度,以及所有发票,费用,票据等.但是我收到语法错误.目标是致电close_account_proc(398985994)

Ok, this is only the second stored procedure I've written. I think you'll get the idea, I'm trying to close a credit line, and all invoices, charges, notes, etc with it. But I get a syntax error.The goal is to 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附近使用,其中第5行的type_acc ='init'和credit_used_acc'.

So, anway, I get this error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@uid_usr := uid_usr from credit_acc where type_acc = 'init' and credit_used_acc ' at line 5.

有什么想法吗?

推荐答案

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 ;

这篇关于mysql存储过程语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:20