2012-09-27 22 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