2012-09-27 21 views
0

下面我已經設置了一個將使用參數循環的過程。然而,我正在測試它的一部分,但得到了不想要的輸出。MySQL空變量不返回正確的情況下

當我選擇p_start爲空時,選擇v_start輸出將狀態爲v_start爲NULL。但我認爲有一個case語句會將v_start重新定義爲1而不是...

有什麼建議嗎?謝謝。

Create procedure counter_loop(p_start int, 
           p_end int, 
           p_step int, 
           p_delim varchar(5)) 
begin 
declare v_start int ; 
declare v_end int ; 
declare v_step int ; 
declare v_sign int; 


-- check p_start 
case p_start 
when null then 
    set v_start := 1; 
else 
    set v_start := p_start; 
end case; 

select v_start; 

回答

0

語法錯了...檢查空的情況下P_START當......與檢查爲空。

case 
when **p_start is** null then 
    set v_start := 1; 
else 
    set v_start := p_start; 
end case; 
0

當你調用存儲過程時,你是說聲明p_start參數爲空嗎?或傳遞一個空字符串?

exec counter_loop(null,10,2,'abc')然後我認爲你的空例將會被它捕獲。

我會推薦你​​在p_start上使用整數檢查而不是null。

像一些事情:

CASE p_start when (len(p_start) > 0 and p_start > 0) then ... 
+0

當我調用counter_loop(null,10,2,'abc')時,我得到p_start爲空。但我想它出來作爲1.如果我使用長度比較的過程,這有幫助嗎?我的意思是長度(空)是空的,不是正面的... – user1682055