0

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

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 ;

在“where 子句”中收到此错误未知列“uname”

4

2 回答 2

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 ;

你会相信你拼错了DELIMETER ???

它应该是 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 ;
于 2012-07-10T19:35:00.913 回答
0

建议:尝试去掉 @@delimiter 的开头和结尾,看看是否可以解决?我在网上找到的示例仅在顶部有分隔符,但没有看到包括底部第二个在内的示例。

于 2012-07-10T19:32:18.363 回答