oracle 将select语句的结果插入到Oracle存储过程中的另一个表中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11631796/
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
Insert result of select statement to another table in Oracle stored procedure
提问by Nikhil Gaur
I am preparing a stored procedure in oracle. In this procedure I have a select statement which will result in multiple rows. Now I want to insert these rows to another table.
我正在准备一个 oracle 的存储过程。在这个过程中,我有一个选择语句,它将产生多行。现在我想将这些行插入到另一个表中。
Please someone tell me it is really urgent.
请有人告诉我这真的很紧急。
UPDATE:
更新:
One thing that I forgot to mention is that I also have to add another column in my result of select statement. This column will contain value of a parameter in this stored procedure.
我忘记提及的一件事是,我还必须在 select 语句的结果中添加另一列。此列将包含此存储过程中的参数值。
Below is the sample stored procedure for this
以下是用于此的示例存储过程
Create or Replace PROCEDURE "My Procedure"
(
my_id in number,
nric in VARCHAR2
)
BEGIN
insert into new_table(my_new_id,field1, field2)
select my_id,table1.field1, table2.field2
from table1, table2
where table1.age=table2.age AND table1.my_nric=nric;
END
In above sample I have my_id in procedure parameter and want to insert that in new_table for each result entry from table1 and table2.
在上面的示例中,我在过程参数中有 my_id,并希望将它插入到 new_table 中,以便为 table1 和 table2 中的每个结果条目。
回答by codingbiz
You can try this
你可以试试这个
INSERT INTO myTable(field1, field2, field3)
SELECT field1, field2, field3
FROM anotherTable
WHERE thisCondition = 'mycondition';