Little and Mickle

All things are difficult before they are easy.

导航

to create table if table do not exist -- to backup and restore table in oracle

1.to backup tblPermission into tblPermissionBak. If tblPermissionBak does not exist, Create the table and insert all data of tblPermission into tblPermissionBak. If tblPermissionBak exists, insert all datas without create table.

declare cnt integer;
Begin
select count(*) into cnt from all_tables where table_name=Upper('tblPermissionBak');
if(cnt<=0) then
   execute immediate 'create table tblPermissionBak as (select * from tblPermission)';
else
   execute immediate 'truncate table tblPermissionBak';
   execute immediate 'insert into tblPermissionBak (select * from tblPermission)';
end if;
End;
/
commit;

2.to retore table
truncate table tblPermission;

insert into tblPermission (select * from tblPermissionBak);

commit;

posted on 2005-09-21 17:01  davidullua  阅读(1047)  评论(0)    收藏  举报