1: delimiter //
2: drop procedure if exists test//
3: create procedure test()
4: begin
5: if @test_id=NULL then
6: select 1,@test_id;
7: else
8: select 2,@test_id;
9: end if;
10: end//
11: delimiter ;
12:
13: call test();
如里@test_id为NULL的话,执行的应该是select 1,@test_id。结果显示该代码执行的是else后的代码块,但显示的@test_id值却为NULL。
如写成如下的样式,则执行正常。
1: delimiter //
2: drop procedure if exists test//
3: create procedure test()
4: begin
5: if @test_id then
6: select 1,@test_id;
7: else
8: select 2,@test_id;
9: end if;
10: end//
11: delimiter ;
12:
13: call test();
Result: