0

下面我设置了一个将使用参数循环的过程。但是,我正在测试它的一部分,但得到了不需要的输出。

当我选择 p_start 为空时,选择 v_start 输出将显示 v_start 为空。但我认为有一个 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;
4

2 回答 2

0

当您调用存储过程时,您是说将 p_start 参数声明为 null 吗?或传递一个空字符串?

exec counter_loop(null,10,2,'abc') 那么我认为你的 null 案例会抓住它。

我建议您对 p_start 使用整数检查而不是 null。

就像是:

CASE p_start when (len(p_start) > 0 and p_start > 0)  then ...
于 2012-09-27T02:18:15.800 回答
0

语法错误...当检查 p_start 是否为空时...检查 IS NULL。

 case 
 when **p_start is** null then
    set v_start := 1;
 else
    set v_start := p_start;
 end case;
于 2012-09-27T02:41:30.717 回答