2016-11-03 38 views
0

我在MySQL中,以下存儲過程..MySQL的程序條件不occour

main: BEGIN 
    DECLARE user_name VARCHAR(65); 
    DECLARE home_path VARCHAR(255); 
    DECLARE home_perm VARCHAR(10); 
    DECLARE num_posts, param_index INT(10); 

    SELECT `account`, `Posts` 
    INTO user_name, num_posts 
    FROM account_info 
    WHERE account = username_in AND password = password_in; 

    IF (user_name = NULL) OR (user_name != username_in) THEN 
    LEAVE main; 
    END IF; 

    SET home_perm = 'LRS'; 

    IF num_posts > 100 THEN 
    SET param_index = 1; 
    SET home_path = 'c:\\folder_1'; 
    ELSEIF num_posts > 200 THEN 
    SET param_index = 2; 
    SET home_path = 'c:\\folder_2'; 
    ELSE 
    SET param_index = 0; 
    SET home_path = 'c:\\folder_0'; 
    END IF; 

    SELECT home_path,home_perm,param_index; 

END 

當我測試用的用戶名這個過程,是不正確,我希望它「離開主」,但即使我做它仍然沒有進入LEAVE主,我能做些什麼來解決這個問題?

回答

0

null值不等於任何值,因此兩個比較都會返回false。使用is null運算符或<=>運算符將變量與空值進行比較。

user_name IS NULL 
+0

這效果更好,謝謝! – MTplus