db2数据库存储过程入门2

例3:
--有输入参数
create procedure test5(in sid integer , out result integer)
language sql
begin

 set result = 0;
 --查询出dtbasic表中主键大于sid的数据数量赋值给 result;
 select count(*) into result from dtbasic where id > sid;

end;
------------------------------------------------
create procedure test6(in sid integer , out result varchar(300))
language sql
begin

 set result = '';
 --查询出dtbasic表中主键是sid的字段title赋值给 result;
 select title into result from dtbasic where id = sid;

end;

数据库调用:call test6(1,?)

例4:
--在存储过程中声明变量
create procedure test7(in sid integer , out result integer)
language sql
begin

 declare a integer;
 set result = 0;
 set a = sid;
 --查询出dtbasic表中主键大于sid的数据数量赋值给 result;
 select count(*) into result from dtbasic where id > a;

end;

------------------------------------------------

create procedure test8(in sid integer , out result varchar(300))
language sql
begin
 
 declare a varchar(300);

 set result = '';
 
 --查询出dtbasic表中主键大于sid的数据数量赋值给 result;
 select title into a from dtbasic where id = sid;
 
 set result = a;
 
end;

数据库调用:call test8(1,?)

你可能感兴趣的:(db2数据库存储过程入门2)