FOr Loop With Insert statement

I have this code but don't know exact syntax. Will this Insert 5 rows into tab1 if the Select statement brings back 5 rows? Do I need to increment or will this happen automatically?

for y in(Select e1.NAME_OF_CLIENT From ENDORSE
                   INNER JOIN ENDORSE_WC290303  e1 ON e1.ENDORSE_ID = e.ENDORSE_ID
                   WHERE e.CARRID = l_Temp_COV_pCARRID AND e.POLNBR = l_Temp_COV_polNbr
               AND e.COV_EFFDT = :pCOV_EFFDT AND e.ENDORSE_CD_NBR = l_Temp_COV_covEffDate) loop
                       
                   INSERT INTO tab1(col1) values(NAME_OF_CLIENT)
                 
end loop;
jknj72Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jknj72Author Commented:
FYI, Being done in SQL Developer
slightwv (䄆 Netminder) Commented:
It will happen automatically.  It will execute 5 insert statements.

For LARGE batches, you might want to commit every X rows with a manually created counter that is incremented in the loop.

Do you have a 'development' database?  Set up a quick and simple test case and try it...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slightwv (䄆 Netminder) Commented:
Missed this.

Change:
INSERT INTO tab1(col1) values(NAME_OF_CLIENT)

to
INSERT INTO tab1(col1) values(y.NAME_OF_CLIENT)

If the loop is named 'Y', you need to prefix the values with that.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sdstuberCommented:
your loop isn't really needed, and will simply consume more cpu, undo, redo, etc by looping.
just do a direct insert for maximum efficiency

INSERT INTO tab1(col1)
    SELECT e1.name_of_client
      FROM endorse INNER JOIN endorse_wc290303 e1 ON e1.endorse_id = e.endorse_id
     WHERE e.carrid = l_temp_cov_pcarrid
       AND e.polnbr = l_temp_cov_polnbr
       AND e.cov_effdt = :pcov_effdt
       AND e.endorse_cd_nbr = l_temp_cov_coveffdate


of course, if you do other stuff inside your loop, then it might be necessary to maintain that structure even if it is inefficient
jknj72Author Commented:
I didn't forget about this question yet guys. I have just been derailed for a little bit and will come back when I am on this part again....Thanks for your patience
jknj72Author Commented:
Actually am using stubers advice, in a different manner, but you gave me the answer I requested so its only fair I give you the points.  Thanks to you both...
slightwv (䄆 Netminder) Commented:
Since you chose to use another Experts advise I suggest you allow us to reopen this so you can split the points.
jknj72Author Commented:
I figured you answered the question and were first you should get the points. I did use Stubers advice to not loop through each value though.
if that's what you want its ok with me

JK
jknj72Author Commented:
how do I do it?
jknj72Author Commented:
Thank you both
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.