在Oracle中建立具有結鉤相同的表

來源:互聯網
上載者:User

在Oracle中建立表結鉤相同或一致的表,其實在許多時候也會派上用場的。方便得很。

例如:存在一張部門表如下:

  1. SQL> select * from dept;  
  2.    
  3. DEPTNO DNAME          LOC  
  4. ------ -------------- -------------  
  5.     50 TRAIN          BOSTON  
  6.     60 MARKET           
  7.     10 ACCOUNTING     NEW YORK  
  8.     20 RESEARCH       DALLAS  
  9.     30 SALES          CHICAGO  
  10.     40 OPERATIONS     BOSTON  
  11.    
  12. 6 rows selected  
  13.   

要建立一張部門表一模一樣的表,即是除卻表名,其它五髒八俯都一樣的表,如下: 

  1. SQL> create table new_dept as select * from dept;  
  2.    
  3. Table created  
  4.    
  5. SQL> select * from new_dept;  
  6.    
  7. DEPTNO DNAME          LOC  
  8. ------ -------------- -------------  
  9.     50 TRAIN          BOSTON  
  10.     60 MARKET           
  11.     10 ACCOUNTING     NEW YORK  
  12.     20 RESEARCH       DALLAS  
  13.     30 SALES          CHICAGO  
  14.     40 OPERATIONS     BOSTON  
  15.    
  16. 6 rows selected  
  17.   

如果你不喜歡建立立的表裡的資料。你只須表屬性相同即可,你就可增加一個條件:rownum=0或者rownum<1  如下所示: 

  1. SQL> create table new_dept1 as select * from dept where rownum<1;  
  2.    
  3. Table created  
  4.    
  5. SQL> select * from new_dept1;  
  6.    
  7. DEPTNO DNAME          LOC  
  8. ------ -------------- -------------  
  9. SQL>  create table new_dept2 as select * from dept where rownum=0;  
  10.    
  11. Table created  
  12.    
  13. SQL> select * from new_dept2;  
  14.    
  15. DEPTNO DNAME          LOC  
  16. ------ -------------- -------------  

這樣的話,有時候在匯入資料測試的時候就方便多了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.