最近使用Oracle匯入匯出資料時,遇到了不少的麻煩!遂對oracle資料庫進行了認真的學習,總結了幾種匯入匯出的命令方法,以備以後查閱。
資料匯出:
1、 將資料庫test完全匯出,使用者名稱system 密碼manager 匯出到d:/daochu.dmp中
exp system/manager@test file=d:/daochu.dmp full=y
2 、將資料庫中system使用者與sys使用者的表匯出
exp system/manager@test file=d:/daochu.dmp owner=(system,sys)
3 、將資料庫中的表inner_notify、notify_staff_relat匯出
exp aichannel/aichannel@testdb2 file= d:/data/newsmgnt.dmp tables=(inner_notify,notify_staff_relat)
4 、將資料庫中的表table1中的欄位filed1以"00"打頭的資料匯出
exp system/manager@test file=d:/daochu.dmp tables=(table1) query=/" where filed1 like 00%/"
上面是常用的匯出,對於壓縮,既用winzip把dmp檔案可以很好的壓縮。 也可以在上面命令後面 加上 compress=y 來實現。
資料匯入:
1 、將d:/daochu.dmp 中的資料匯入 test資料庫中。
imp system/manager@test file=d:/daochu.dmp imp aichannel/aichannel@hust full=y file=file= d:/data/newsmgnt.dmp ignore=y
上面可能有點問題,因為有的表已經存在,然後它就報錯,對該表就不進行匯入。 在後面加上 ignore=y 就可以了。
2 、將d:/daochu.dmp中的表table1 匯入
imp system/manager@test file=d:/daochu.dmp tables=(table1)
基本上上面的匯入匯出夠用了。不少情況要先是將表徹底刪除,然後匯入。
注意: 操作者要有足夠的許可權,許可權不夠它會提示。 資料庫時可以連上的。可以用tnsping test 來獲得資料庫test能否連上。
以上記載,只是oracle資料匯入匯出的最基本方法,在實際應用中會有各種因素影響匯入匯出的結果,所以要靈活運用這些最基本的命令,但也要統籌整個oracle啟動並執行環境來考慮問題。