How can I create table as select (CTAS) in oracle?

2019-02-25 21:23发布

问题:

I need to use CTAS (Create Table As Select) to create a table named Au_Books_ZL that contains au_id, fname, lname, title_id, title, Pub_id, price and revenue (which is price*sales).

I have browsed other questions online, but they don't show how to include all the attributes (lname, fname, title_id ect.) in the query. How could I write up my CTAS to create the new table?

回答1:

The syntax for creating a table would be something like

CREATE TABLE au_books_zl
AS
  SELECT au_id,
         fname,
         lname,
         title_id,
         title,
         pub_id,
         price,
         price * sales as revenue
    FROM <<whatever tables you need to select from>>
   WHERE <<whatever conditions you need to apply>>