一个简单的将Oracle生产库定期备份到备份库的方法
先编写bat文件:
exp db_user/db_pwd@SourceDatabase owner=db_user file=d:\rec\bk_data.dmp
sqlplus db_user/db_pwd@localDatabase @del.sql
imp db_user/db_pwd@localDatabase fromuser=db_user touser=db_user file=d:\rec\bk_data.dmp
然后编写del.sql:
DECLARE
TYPE name_list IS TABLE OF VARCHAR2(40);
TYPE type_list IS TABLE OF VARCHAR2(20);
Tab_name name_list:=name_list();
Tab_type type_list:=type_list();
sql_str VARCHAR2(500);
BEGIN
sql_str := 'select uo.object_name,uo.object_type from user_objects uo where uo.object_type not in(''INDEX'',''LOB'') order by uo.object_type desc';
EXECUTE IMMEDIATE sql_str BULK COLLECT INTO tab_name,tab_type;
FOR i IN Tab_name.FIRST.. Tab_name.LAST LOOP
sql_str := 'DROP ' || Tab_type(i) || ' ' || Tab_name(i);
EXECUTE IMMEDIATE sql_str;
END LOOP;
END;
.
/
exit;
目前维护的开源产品:https://gitee.com/475660