您的位置:首页 > 数据库 > Oracle

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

2005-09-21 17:01 1016 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐