在做資料遷移的場景中,會碰到含有觸發器,約束等條件的資料。遷移時候要注意先關閉觸發器,等待遷移完成後再開啟。具體操作看參考下面例子:
在目標庫上建立資料泵目錄
在目標庫上建立資料泵目錄sys使用者建立
create directory dump_dir as ‘目錄地址’
select * from Dba_Directories
——給定user使用者dump許可權
grant read,write on directory dump_dir to user
在源庫上匯出資料:
expdp system/oracle directory=dump_dir dumpfile=user。dmp schemas=user logfile=user。log
匯出表結構:
impdp system/oracle directory=dump_dir dumpfile=user。dmp sqlfile=user。sql logfile=userimp。log
在目標庫上建立表
SQL>@目錄地址/user。sql
匯入資料前關閉約束和觸發器:
SQL>set heading off
SQL>select ‘alter table ’||table_name||‘ disable constraint ’||constraint_name||‘;’ from user_constraints;
SQL>alter table table_name disable constraint constraint_name;
SQL>select ‘alter trigger ’||trigger_name||‘ disable;’ from user_triggers;
SQL>alter trigger trigger_name disable
匯入資料:
export ORACLE_SID=SID
$impdp system/oracle directory=dump_dir dumpfile=javaoanew。dmp table_exists_action=append logfile=javaoaimpnew。log
匯入資料後開啟約束和觸發器:
SQL>select ‘alter table ’||table_name||‘ enable novalidate constraint ’||constraint_name||‘;’ from user_constraints;
SQL>alter table table_name enable novalidate constraint constraint_name;
SQL>select ‘alter trigger ’||trigger_name||‘ enable;’ from user_triggers;
SQL>alter trigger trigger_name enable
連線應用測試,一切OK。