在Oracle中建立表結鉤相同或一致的表,其實在許多時候也會派上用場的。方便得很。
例如:存在一張部門表如下:
- SQL> select * from dept;
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 50 TRAIN BOSTON
- 60 MARKET
- 10 ACCOUNTING NEW YORK
- 20 RESEARCH DALLAS
- 30 SALES CHICAGO
- 40 OPERATIONS BOSTON
-
- 6 rows selected
-
要建立一張部門表一模一樣的表,即是除卻表名,其它五髒八俯都一樣的表,如下:
- SQL> create table new_dept as select * from dept;
-
- Table created
-
- SQL> select * from new_dept;
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- 50 TRAIN BOSTON
- 60 MARKET
- 10 ACCOUNTING NEW YORK
- 20 RESEARCH DALLAS
- 30 SALES CHICAGO
- 40 OPERATIONS BOSTON
-
- 6 rows selected
-
如果你不喜歡建立立的表裡的資料。你只須表屬性相同即可,你就可增加一個條件:rownum=0或者rownum<1 如下所示:
- SQL> create table new_dept1 as select * from dept where rownum<1;
-
- Table created
-
- SQL> select * from new_dept1;
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
- SQL> create table new_dept2 as select * from dept where rownum=0;
-
- Table created
-
- SQL> select * from new_dept2;
-
- DEPTNO DNAME LOC
- ------ -------------- -------------
這樣的話,有時候在匯入資料測試的時候就方便多了。