oracle 选择到Oracle中的临时表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28653276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:45:36  来源:igfitidea点击:

Select into a temporary table in Oracle

oracleplsqlsqlplus

提问by Sait

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.

在我的真实示例中,子查询(select * from student)更复杂。

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.

我想在存储过程中使用它,所以我不想创建表本身。我只想通过使用临时表使我的代码更具可读性。

回答by Martina

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;

回答by kiko tefacka

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

如果表 temp 不存在,则必须创建它。

 CREATE TABLE temp as
    SELECT * FROM student;

回答by OldProgrammer

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;