问题
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