tags:

views:

59

answers:

2

Hi

I would like to create a temporary table in a Oracle database

something like

Declare table @table (int id)

In SQL server

And than populate it with a select statement

Is it possible?

Thanks

+3  A: 

Yep, oracle has temporary tables. Here is a link to an AskTom article describing them.
And here is the official oracle CREATE TABLE documentation (scroll down to the CREATE GLOBAL TEMPORARY section)
And an example:

CREATE GLOBAL TEMPORARY TABLE today_sales
   ON COMMIT PRESERVE ROWS 
   AS SELECT * FROM orders WHERE order_date = SYSDATE;
hamishmcn
No downvote, but I would never recommend a CREATE TABLE AS SELECT for a global temporary table - a less experienced developer might get the wrong idea that they have to populate GTTs this way every time. Sure, this is a convenient way of copying the definition from another table, but the example will probably confuse some people.
Jeffrey Kemp
+3  A: 

Just a tip.. Temporary tables in Oracle are different to SQL Server. You create it ONCE and only ONCE, not every session. The rows you insert into it are visible only to your session, and are automatically deleted when you end you session ( or end of the transaction, depending on which "ON COMMIT" clause you use).

Matthew Watson