2011-12-28 116 views
1
DECLARE vote_id INT; 
    select id from votes where votes.question_id = question_id and vote_type_id = 3 into vote_id; 

    if vote_id is null then 
     ...do A 
    else 
     ...do B 
    end if; 

該條件應該是true並執行一部分代碼但總是執行B部分。
如何使用選擇與if語句?非常感謝你。MySQL存儲過程if語句

+1

也許'vote_id'永遠不會爲您的查詢爲空? – adarshr 2011-12-28 09:35:23

+0

我在mysql中執行'select id ...'並返回id – VvDPzZ 2011-12-28 09:39:27

回答

1

嘗試select id from votes where votes.question_id = question_id and votes.vote_type_id = 3 into vote_id;