我正在准备一个 oracle 的存储过程。在这个过程中,我有一个选择语句,它将产生多行。现在我想将这些行插入到另一个表中。
请有人告诉我这真的很紧急。
更新:
我忘记提及的一件事是,我还必须在 select 语句的结果中添加另一列。此列将包含此存储过程中的参数值。
以下是用于此的示例存储过程
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
在上面的示例中,我在过程参数中有 my_id,并希望将它插入到 new_table 中,以便为 table1 和 table2 中的每个结果条目。
最佳答案
你可以试试这个
INSERT INTO myTable(field1, field2, field3)
SELECT field1, field2, field3
FROM anotherTable
WHERE thisCondition = 'mycondition';
关于oracle - 将select语句的结果插入到Oracle存储过程中的另一个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11631796/