Create a table with the same hooks in Oracle

Source: Internet
Author: User
Tags dname

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:

 
 
  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.   

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:

 
 
  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.   

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:

 
 
  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. ------ -------------- -------------  

In this way, sometimes it is much easier to import data for testing.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.