为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:
【操作系统】:
【CPU】:
【问题描述】*:
create or replace procedure tmpc2 ()
as
v_num int;
c cursor for select id from tmp2;
begin
execute immediate 'drop table if exists tmp2';
execute immediate 'create temporary table tmp2( id int,name varchar(200))';
open c;
fetch c into v_num;
while c %found loop
print v_num;
fetch c into v_num;
end loop;
close c;
execute immediate 'drop table tmp2';
end;
编译报错,提示无效的表和视图
直接手工创建临时表
create temporary table tmp2( id int,name varchar(200));
可以正常编译存储过程
但无法调用
"无效的表和视图"是因为在执行脚本时c游标所调用的 tmp2 表在系统数据字典中不存在,所以语义检查时直接提示对象不存在了。
“对象定义被修改”是因为你的脚本中对库表对象通过execute immediate 进行了ddl修改,造成执行过程中数据库对象字典数据版本发生改变,与进入函数时的版本不一致,所以会提示“对象定义被修改”。
你可以试一下把针对动态对象的处理过程也通过 execute immediate 执行,例如:
create or replace procedure tmpc2 () as begin execute immediate 'drop table if exists tmp2'; execute immediate 'create temporary table tmp2( id int,name varchar(200))'; EXECUTE IMMEDIATE ' declare v_num int; c cursor for select id from tmp2; begin open c; fetch c into v_num; while c %found loop print v_num; fetch c into v_num; end loop; close c; end; '; execute immediate 'drop table tmp2'; end;