Select into a temporary table in Oracle

∥☆過路亽.° 提交于 2019-12-21 03:39:19

问题


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.


回答1:


Then perhaps you need to do something like this:

declare
   type t_temp_storage is table of student%rowtype;
   my_temp_storage t_temp_storage;
begin
   select * bulk collect into my_temp_storage from student;
   for i in 1..my_temp_storage.count
    loop
    dbms_output.put_line('here I am '||my_temp_storage(i).stuid);
   end loop; 
 end;



回答2:


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

 CREATE TABLE temp as
    SELECT * FROM student;



回答3:


You don't "select" into a temp table. If you want to insert into a temp table from the results of a select:

insert into temp
select * from student;


来源:https://stackoverflow.com/questions/28653276/select-into-a-temporary-table-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!