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;
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;
相关文章推荐
- Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, do
- oracle不提供CREATE TABLE IF NOT EXIST方式创建表
- Do not delete and re-create if the object already exist
- 51 You have not configured Oracle Managed Files (OMF) in your database. You do not want to scan the
- 【Oracle问题集5】ORA-55622: DML, ALTER and CREATE UNIQUE INDEX operations are not allowed on table
- Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead
- Oracle:Create tablespace and move table to another tablespace
- How to backup and restore database in SQL Server
- Oracle 10g 异常:ORA-01658:unable to create INITIAL extent for segmnet in tablespace SYSTEM
- How to use outline levels to create a table of contents (TOC) in Word 2003 and in Word 2002
- Oracle 10g 异常:ORA-01658:unable to create INITIAL extent for segmnet in tablespace SYSTEM
- DROP TABLE IF EXISTS” in Oracle and SQL Server
- 本地提交SVN报错 提交文件 is not known to exist in the repository and is not part of the commit, yet its child
- 【Android】Do not requestWindow.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your th
- <3>createTableIfNotExist
- svn: is not known to exist in the repository and is not part o
- How do I tell if a regular file does not exist in bash?
- org.apache.hadoop.hbase.DoNotRetryIOException: Class org.apache.phoenix.coprocessor.MetaDataEndpointImpl cannot be loaded Set hbase.table.sanity.checks to false at conf or table descriptor if you want
- DROP TABLE IF EXISTS” in Oracle and SQL Server
- “DROP TABLE IF EXISTS” in Oracle and SQL Server