create global temporary table tablename ( col1 varchar2(10), col2 number ) on commit preserve(delete) rows ; --o
create global temporary table tablename (
col1 varchar2(10),
col2 number
) on commit preserve(delete) rows ;
--on commit delete rows 说明临时表是事务指定,每次提交后oracle将截断表(删除全部行)
---------------------------------------
在oracle8i中,可以创建以下两种临时表:
1。会话特有的临时表
create global temporary ( )
on commit preserve rows;
2。事务特有的临时表
create global temporary ( )
on commit delete rows;
create global temporary table mytemptable
所建的临时表虽然是存在的,但是你试一下insert 一条记录然后用别的连接登上去select,记录是空的,明白了吧。
下面两句话再贴一下:
--on commit delete rows 说明临敀?表是事务指定,每次提交后oracle将截断表(删除全部行)
--on commit preserve rows 说明临时表是会话指定,当中断会话时oracle将截断表。
procedure 执行一系列的操作
package 可以在其中定义一些量、函数、过程等;
存储过程里不能直接使用ddl语句,,所以只能使用动态sql语句来执行
create procedure pro
as
str varchar2(100);
begin
str := 'create global temporary table admin_work_area
(startdate date,
enddate date,
class char(20))
on commit delete rows’;
execute immediate str;
end;
删除:
truncate table mytemptable
drop table mytemptable
ora-22992: 无法使用从远程表选择的 lob 定位器
解决办法:
可以先创建一个临时表,然后把远程有lob字段的表克隆到临时表中,然后再进行链接操作
1.本地创建临时表
sql代码
create global temporary table photo_temp as select * from photo@photo_link where 1=2 ;
2.用database link导入远程数据到临时表
sql代码
insert into photo_temp select * from photo@photo_link;--不要commit;否则临时表中数据消失
3.把临时表数据插入到永久表中:
sql代码
insert into photo select * from photo_temp;
commit;
实例:
create global temporary table pic_temp as select * from wh_registerpic@ogdpshdb where 1=2 ;
insert into pic_temp select * from wh_registerpic@ogdpshdb;
insert into wh_registerpic select * from pic_temp;
commit;
删除临时表:
truncate table pic_temp ;
drop table pic_temp ;
解决普通用户在存储过程中无权建临时表问题:
在包头中加 authid current_user
例子:
create or replace package wh_info_output authid current_user is
-- author :
-- created : 2014年9月2日 15:27:25
-- purpose :
--删除原有数据导入全部数据
procedure sp_wh_info_output_all(fid in number default 1);
-- public type declarations
--传入参数默认0:导入没有的数据 1:删除原有数据导入全部数据
procedure sp_wh_info_output(fid in number default 0);
--导入wh_registerpic表(含有blog字段) 0:导入没有的数据 1:删除原有数据导入全部数据
procedure sp_wh_pic_bloginfo_output(fid in number default 0);
end wh_info_output;
--导入wh_registerpic表(含有blog字段) 0:导入没有的数据 1:删除原有数据导入全部数据
procedure sp_wh_pic_bloginfo_output(fid in number default 0)
is
str varchar2(300);
begin
if fid = 0 then
str:='create global temporary table pic_temp as select * from wh_registerpic@ogdpshdb where 1=2';
execute immediate str;
str:='insert into pic_temp select * from wh_registerpic@ogdpshdb w where (w.wellid, w.pictypecode, w.versionno, w.picfilename) not in (select wellid, pictypecode, versionno, picfilename from wh_registerpic)';
execute immediate str; ----使用动态sql语句来执行
str:='insert into wh_registerpic select * from pic_temp';
execute immediate str;
end if;
end sp_wh_pic_bloginfo_output;
在centos 6.4下安装oracle 11gr2(x64)
oracle 11gr2 在vmware虚拟机中安装步骤
debian 下 安装 oracle 11g xe r2
本文永久更新链接地址: