Question : for loop in oracle

for serv_prc_rec in serv_prc_cur(get_ship_interface_rec.item_id
                                          ,get_ship_interface_rec.price_code) loop      
v_price := serv_prc_rec.price;
dbms_output.put_line('serv_prc_rec price = '||serv_prc_rec.price);
-- If the above loop fetched null or no records then  the below
for serve_ar_interface_rec in serve_ar_interface_cur(get_ship_interface_rec.item_id) loop             v_price := serve_ar_interface_rec.std_price;
 dbms_output.put_line('interface price = '||get_ship_interface_rec.std_price);      
------------------
My requirement is if the ist loop returns null or no records then go to the 2nd loop. How do I do that. Here in this case 1st loop does not have any price so I need to get the price from the 2nd loop
But I am not able to get there. How to handle this

Answer : for loop in oracle

easiest way, create a boolean variable set it to false before the first loop, set it to true inside the loop

if the first variable is still false after the first loop, then the loop found nothing and do the 2nd loop

v_loop_check := FALSE
for serv_prc_rec in serv_prc_cur(get_ship_interface_rec.item_id
                                          ,get_ship_interface_rec.price_code) loop      
v_loop_check := TRUE;
v_price := serv_prc_rec.price;
dbms_output.put_line('serv_prc_rec price = '||serv_prc_rec.price);
end loop;

if not v_loop_check  then
-- If the above loop fetched null or no records then  the below
for serve_ar_interface_rec in serve_ar_interface_cur(get_ship_interface_rec.item_id) loop             v_price := serve_ar_interface_rec.std_price;
 dbms_output.put_line('interface price = '||get_ship_interface_rec.std_price);      
end if;
Random Solutions  
 
programming4us programming4us