Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select into a temporary table in Oracle

I am trying to do something like the following,

select * into temp from (select * from student);

It gives me the following error,

ERROR at line 1:
ORA-00905: missing keyword

In my real example the subquery (select * from student) is more complex.

I want to use this in a stored procedure, so I don't want to create the table itself. I just want to make my code more readable by using a temp table.

like image 351
Sait Avatar asked Feb 22 '15 00:02

Sait


People also ask

Does SELECT into create a temporary table?

After creating the table, we can insert data into it as the persisted tables. At the same time, we can create a temporary table using the SQL SELECT INTO statement command.

How do I access a temporary table in SQL?

Now, to see where this table exists; go to “Object Explorer -> Databases -> System Databases-> tempdb -> Temporary Tables”. You will see your temporary table name along with the identifier.


1 Answers

If the table temp does not exist, you have to create it.

 CREATE TABLE temp as
    SELECT * FROM student;
like image 164
kiko tefacka Avatar answered Sep 17 '22 15:09

kiko tefacka