Akaitenshi Akaitenshi - 23 days ago 8
SQL Question

Create additional columns when using "Create Table As"

I am creating a table using the

CREATE TABLE AS
Statement. Script looks like this :

CREATE TABLE table2
AS
SELECT column1, column2, ..., columnN
FROM table1
WHERE ROWNUM <= 50;


My question is, can I create additional columns on table2 that don't exist in table1 inside the
CREATE TABLE AS
Statement or do I have to resort to
ALTER
afterwards?

EDIT: For example table1 contains ID, FULLNAME, STATUS and I wanna add a column somewhere in between called AGE

I am using Oracle Sql

Answer

You can add whatever you'd like to the SELECT

CREATE TABLE table2
AS
  SELECT column1, column2, ..., columnN, 
         trunc(months_between(birth_date,sysdate)/12) age,
         'Some string' another_column
  FROM table1
  WHERE ROWNUM <= 50;