1

How to create table with existing table structure without iterate row by row like this in Oracle? Thanks in Advance.

CREATE TABLE new_table
  AS (SELECT *
      FROM old_table WHERE 1=2);
sunleo
  • 10,589
  • 35
  • 116
  • 196

3 Answers3

3

If you are worried about iterating through the table:

CREATE TABLE new_table
  AS (SELECT *
      FROM (select * old_table where rownum = 1) t
      WHERE 1=2
     );
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

I have already read about this.. Hope it gives a Detailed explanation to you..

What we ended up doing in this clients case was to replace the “WHERE 1=2” with a clause that equated the primary key of the table with an impossible value for that key, in this case the ID was being passed in as a GUID (a hexadecimal value) so we use a “WHERE KEY=HEX(00)” and got a low cost unique index lookup instead of a costly full table scan.

http://www.dba-oracle.com/oracle_tips_ault_where_1_equals_2_parallel_.htm

Thanks to Burleson Consulting

Maheswaran Ravisankar
  • 17,652
  • 6
  • 47
  • 69
0

I'm not sure on the exact Oracle syntax but in virtually any SQL if you open up the other table using a GUI tool there are options both to generate a create script statement for the table and to backup the table without data.

Either of those will do what you need.

Tim B
  • 40,716
  • 16
  • 83
  • 128