Creating tables in Oracle to hook the same or consistent tables can also be used in many cases. Convenient.
For example, a department table exists as follows:
- 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
-
Create a table with the same department table, that is, a table with the same name except the table name and the other five dirty tables, as shown below:
- 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
-
If you do not like the data in the newly created table. You only need to have the same table attributes. You can add a condition: rownum = 0 or rownum <1 is as follows:
- 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
- ------ -------------- -------------
In this way, sometimes it is much easier to import data for testing.