create or replace procedure name_pro
as
v_sql1 varchar2(4000);
isExists number(2);
cursor checkExists is select count(1) from all_tables where owner='ZHENYUAN' AND TABLE_NAME='TABLENAME';
begin
open checkExists;
fetch checkExists into isExists;
if isExists=1 then
execute immediate 'drop table temp_table_1';
end if; v_sql1 := 'CREATE GLOBAL TEMPORARY TABLE temp_table_1 ON COMMIT PRESERVE ROWS as select * from ...';
execute immediate v_sql1;
end;跟表名没有关系,主要是思路,多谢各位
as
v_sql1 varchar2(4000);
isExists number(2);
cursor checkExists is select count(1) from all_tables where owner='ZHENYUAN' AND TABLE_NAME='TABLENAME';
begin
open checkExists;
fetch checkExists into isExists;
if isExists=1 then
execute immediate 'drop table temp_table_1';
end if; v_sql1 := 'CREATE GLOBAL TEMPORARY TABLE temp_table_1 ON COMMIT PRESERVE ROWS as select * from ...';
execute immediate v_sql1;
end;跟表名没有关系,主要是思路,多谢各位
删除( On commit delete rows)还是session(On commit preserve rows) 结束后删除就可以自动删除了
2、在过程里,用动态sql来实现咯
而且进程进行表的删除会造成很多碎片,使服务器性能下降。
我看你的过程里面是建立临时表,而不是删除,删除表使用drop
在存储过程中
1。判断临时表是否存在,如果不存在创建;
2。如果临时表存在,因为是不同的会话,是看不到其中的数据的,那么向其中插入数据(因为drop表是会引起并发问题的)
这样考虑对吗?另外,大虾,如果方便,能不能给我一个相关的例子参考一下。。
多谢了!
'CREATE GLOBAL TEMPORARY TABLE temp_table_1 ON COMMIT PRESERVE ROWS as select * from ...';与
'CREATE GLOBAL TEMPORARY TABLE temp_table_1 ON COMMIT PRESERVE ROWS as select * from ... where 1=2'结果一样,没有数据的,只存在结构,想要数据,要多一个步骤:
insert into temp_table_1 select * from ...;