開發人員常用的Oracle匯入/匯出命令

來源:互聯網
上載者:User

作為我們開發人員經常使用exp匯出某一個使用者下的所有對象從某一個資料庫,
然後匯入。通常匯入的時候總是會遇到一些意想不到的問題,其中一個問題就是資料庫中已經存在同名對象,
同時也為那些比較複雜的參數而煩惱。其實對於我們,只需要做下面三個動作,就能順利完成你的匯入匯出工作:
1.匯出
   Exp  <username>[/<password>][@<connect_string>] Owner=<user_name> File=<filename.dmp>

2.Drop掉目標使用者下的所有對象
   執行下面的語句: 

 1declare     
 2    cursor c_cursor is 
 3    select OBJECT_NAME,OBJECT_TYPE
 4    from user_objects 
 5    where OBJECT_TYPE IN ('TABLE','VIEW',
 6                         'PROCEDURE','FUNCTION',
 7                         'PACKAGE','PACKAGE BODY',
 8                         'SEQUENCE','MATERIALIZED VIEW',
 9                         'SYNONYM','TYPE','TYPE BODY')
10    ORDER BY OBJECT_TYPE,OBJECT_NAME;
11    message varchar2(100);    
12    errorNums integer ;
13begin    
14    errorNums := 0;
15    dbms_output.put_line('Dropping objects');
16    FOR tab_rec IN c_cursor    loop        
17        dbms_output.put_line('dropping ' || tab_rec.OBJECT_TYPE || ' '    || TAB_REC.OBJECT_NAME);
18        begin
19            execute immediate 'drop ' || TAB_REC.OBJECT_TYPE || ' ' || tab_rec.OBJECT_NAME;        
20        exception
21            when others then
22                errorNums := errorNums + 1;
23                dbms_output.put_line('dropping err.');
24                dbms_output.put_line(sqlerrm);
25        end;
26    end loop;    
27    if errorNums>0 then
28        dbms_output.put_line('Finished with error. Please execute again.');
29    else
30        dbms_output.put_line('Finished');
31    end if;    
32end;

   執行上面的語句一定要小心,因為它是不可恢複的.
   第二,如果發現執行中有一些問題,某些對象不能被刪除掉,那可能是對象之間有一種依賴關係,重新執行一遍
2.匯入
   Exp  <username>[/<password>][@<connect_string>]    FromUser=<user_name>     ToUser=<user_name>     File=<fileName.dmp>

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.