orcale数据库备份表和删除表

1、tablenamearray为表名称的数组;

2、suffix为新生成表的后缀;

declare 
type tablenamearray is VARRAY(1000) of varchar2(1000); 
tabel_names tablenamearray := tablenamearray('department','cim_table_relation','cim_field_dictionary'); 
total integer; num integer; 
suffix varchar2(20):='_x'; 
begin total := tabel_names.count;
 FOR i in 1 .. total 
    LOOP 
        select count(1) into num from user_tables where table_name = upper(tabel_names(i) || suffix); 
        if num > 0 then
           execute immediate 'drop table ' || tabel_names(i) || suffix; end if; 
           execute immediate 'create table ' || tabel_names(i) || suffix || ' as select * from ' || tabel_names(i); 
           --dbms_output.put_line(i || ':' || tabel_names(i)); 
    END LOOP;
end; 

 

你可能感兴趣的:(oracle)