How can I create a copy of an Oracle table and add new columns to it in same statement? [closed]

StackOverflow https://stackoverflow.com/questions/21872665

  •  13-10-2022
  •  | 
  •  

Question

How can I create a copy of an Oracle table and add new columns to it in same statement? I guess there should be some function. Please help.

Était-ce utile?

La solution

You try this way

CREATE TABLE TEST02
AS
SELECT  COL1                            AS COL3
,       CAST(COL2 AS VARCHAR2(20))      AS COL4
,       CAST(NULL AS DATE)              AS COL5
FROM    TEST01;

Note: I assumed the new column to hold NULL values. COL1 and COL2 is already present in Table 1 and copied into Table 2 as COL3 and COL4 where as COL5 is newly created

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top