I'm using following statement to create a duplicate table with data. But i'm curious to know whether this statement preserves the column order of the old_table in the new_table as it is. Since i need to compare some column data of 2 tables later using MINUS statement.
CREATE TABLE new_table
AS
SELECT *
FROM old_table
Below is the minus statement used to compare. In the following statement cols are queried from ALL_TAB_COLUMNS meta data table.
SELECT COUNT(*) FROM (SELECT cols FROM old_table MINUS (SELECT cols FROM new_table))
Below is the meta data query to get column list in the order.
SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'new_table'
SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'old_table'
My question, Is column order preserved in both new_table and old_table when copied using CREATE TABLE new_table AS SELECT statement mentioned above?
Yes, The New table will have columns exactly in same order as your select
query.