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.
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.
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.
You can try this
INSERT INTO myTable(field1, field2, field3)
SELECT field1, field2, field3
FROM anotherTable
WHERE thisCondition = 'mycondition';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With