db2数据库存储过程入门4

例6:

--在存储过程中声明变量
--在存储过程中建立临时表
--在存储过程中使用简单游标
create procedure test11(in sid integer)
language sql
begin

 declare a integer;
 declare global temporary table session.dtdoctype
 (
  id integer,
  parentid integer,
  name varchar(300)
 );
 
 --查询表dtdoctype中的数据,插入到临时表session.dtdoctype中
 insert into session.dtdoctype select id,parentid,name from dtdoctype where parentid = sid;
 
 begin
  --将临时表session.dtdoctype中的所有数据存到游标Ydtdoctype中
  --with return将结果集返回
  declare Ydtdoctype cursor with return for select * from session.dtdoctype;
  
  open Ydtdoctype;--打开游标
 
 end;
 drop table session.dtdoctype;
end;
解释:通过call test(1)在数据库做来调用存储过程 ,会出现:
SQL0910N  SQL 语句不能访问在其上的修改被暂挂的对象。  SQLSTATE=57007
原因是在存储过程关闭前进行了drop table session.dtdoctype,所有查询不到。
 要是注释了drop table

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值