例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