Link to home
Start Free TrialLog in
Avatar of jknj72
jknj72

asked on

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;
Avatar of jknj72
jknj72

ASKER

FYI, Being done in SQL Developer
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jknj72

ASKER

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
Avatar of jknj72

ASKER

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...
Since you chose to use another Experts advise I suggest you allow us to reopen this so you can split the points.
Avatar of jknj72

ASKER

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
Avatar of jknj72

ASKER

how do I do it?
Avatar of jknj72

ASKER

Thank you both