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;
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
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
if that's what you want its ok with me
JK
ASKER
how do I do it?
ASKER
Thank you both
ASKER