关于存储过程中临时表的问题,返回临时表数据时,提示 PL/SQL: ORA-00942: table or view does not exist
具体代码如下:createorreplaceproceduresp_tt(ref_cursoroutsys_refcursor)asstrvarchar2(1000);s...
具体代码如下:
create or replace procedure sp_tt(
ref_cursor out sys_refcursor
)as
str varchar2(1000);
str1 varchar2(1000);
str2 varchar2(50);
str3 varchar2(50);
istb number:=0;
begin
select count(1) into istb from all_tables where TABLE_NAME = 'TMP_CE' ;
IF istb>0 THEN
BEGIN
str2:='DROP TABLE tmp_ce';
str3:='TRUNCATE TABLE tmp_ce';
execute immediate str3;
commit;
execute immediate str2;
commit;
END;
END IF;
begin
--创建临时表
str:='create global TEMPORARY table tmp_ce ON COMMIT DELETE ROWS
as select waco,wamcu,count(wadoco) nums from proddta.f4801 a
where a.wadcto=''W4'' and a.wasrst<''95'' group by waco,wamcu';
execute immediate str;
end;
--插入数据
begin
str1:='insert into tmp_ce select waco,wamcu,count(wadoco) nums from proddta.f4801 a
where a.wadcto=''W4'' and a.wasrst<''95'' group by waco,wamcu';
--select * from tmp_ce;
execute immediate str1;
end;
--commit;
--返回临时表数据
open ref_cursor for select * from tmp_ce;
end; 展开
create or replace procedure sp_tt(
ref_cursor out sys_refcursor
)as
str varchar2(1000);
str1 varchar2(1000);
str2 varchar2(50);
str3 varchar2(50);
istb number:=0;
begin
select count(1) into istb from all_tables where TABLE_NAME = 'TMP_CE' ;
IF istb>0 THEN
BEGIN
str2:='DROP TABLE tmp_ce';
str3:='TRUNCATE TABLE tmp_ce';
execute immediate str3;
commit;
execute immediate str2;
commit;
END;
END IF;
begin
--创建临时表
str:='create global TEMPORARY table tmp_ce ON COMMIT DELETE ROWS
as select waco,wamcu,count(wadoco) nums from proddta.f4801 a
where a.wadcto=''W4'' and a.wasrst<''95'' group by waco,wamcu';
execute immediate str;
end;
--插入数据
begin
str1:='insert into tmp_ce select waco,wamcu,count(wadoco) nums from proddta.f4801 a
where a.wadcto=''W4'' and a.wasrst<''95'' group by waco,wamcu';
--select * from tmp_ce;
execute immediate str1;
end;
--commit;
--返回临时表数据
open ref_cursor for select * from tmp_ce;
end; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询