This content has been marked as final. Show 7 replies
why do you want to loop
insert into table2 select column1,column2..... column19,'x' from table2
select * should not be used in production code. Good design means that you would know your columns, and you should code those columns explicitly
I'm not sure that I understand what you are asking. If you are asking whether there is a more efficient way to do this, it would be to use a single SQL statement
If you are asking something else, can you explain exactly what you are trying to accomplish?
INSERT INTO my_table( col1, col2, ..., col20 ) SELECT col1, col2, ... , col19, 'G' FROM my_table
declare ... begin for r in (select * from my_table) loop insert into my_table (...) values (...) end loop; end; /
If you are not doing any business check inside the FOR LOOP, we can remove this with a simple SQL query.
No need of the loop-by-loop processing making the operation slow.
Just use the query that others suggested above. That should be fine.
Please let us know if you have other business constraints.
I'm doing some businees inside the for, so i need the for loop
Try doing -1 person found this helpful
declare ... begin for r in (select col1,col2,col3...col20 from my_table) loop insert into my_table (col1,col2,col3,...,col20) values (r.col1,r.col2,...,'G'); end loop; end; /
"values" keyword will be need. Is the business scenario something that can't be handled in sql.Would suggest you to share the logic you are trying to implement may be people will be able to suggest better option.