为什么此过程会引发“未知列”错误

时间:2012-07-10 19:25:01

标签: mysql stored-procedures

我有这个程序,但是这会引发“未知列”#39;错误

USE dhod;
DELIMETER @@
CREATE PROCEDURE sp_drive_size(IN uname VARCHAR(100),IN size INT)
BEGIN
    DECLARE dsize INT DEFAULT 0;
    DECLARE new_size INT DEFAULT 0;
    SELECT drive_size INTO dsize FROM profile WHERE username = uname;
    SET new_size=dsize+size;
    UPDATE profile SET drive_size=new_size WHERE username = uname; 
END @@ 
DELIMETER ;

我收到此错误 未知列' uname'在' where子句'

2 个答案:

答案 0 :(得分:1)

这是您的原始代码

USE dhod;
DELIMETER @@
CREATE PROCEDURE sp_drive_size(IN uname VARCHAR(100),IN size INT)
BEGIN
    DECLARE dsize INT DEFAULT 0;
    DECLARE new_size INT DEFAULT 0;
    SELECT drive_size INTO dsize FROM profile WHERE username = uname;
    SET new_size=dsize+size;
    UPDATE profile SET drive_size=new_size WHERE username = uname; 
END @@ 
DELIMETER ;

你会相信你拼写错误的DELIMITER ???

它应该是DELIMITER(我会将其更改为$$)

USE dhod;
DELIMITER $$
CREATE PROCEDURE sp_drive_size(IN uname VARCHAR(100),IN size INT)
BEGIN
    DECLARE dsize INT DEFAULT 0;
    DECLARE new_size INT DEFAULT 0;
    SELECT drive_size INTO dsize FROM profile WHERE username = uname;
    SET new_size=dsize+size;
    UPDATE profile SET drive_size=new_size WHERE username = uname; 
END $$
DELIMITER ;

答案 1 :(得分:0)

建议:尝试摆脱起始和结束@@ delimiter以查看是否修复了它?我在网上发现的例子只有顶部的分隔符,但没有看到包括底部第二个的例子。