Question : Newbee - Is there a way to loop resultset in sqlplus script?

I'd like to know if its possible to loop through a resultset that returns 'store' (1,2,3,4,5,7,9,11, etc) and uses 'store' as a variable for another query and how its done, any examples?

Query 1) Store

SELECT store FROM DB1 ORDER BY store


Query 2)

SELECT * FROM DB2 WHERE storenum = DB1.store


So in the example above Query2 would loop 8 times (1,2,3,4,5,7,9,11)

SELECT * FROM DB2 WHERE storenum = 1
SELECT * FROM DB2 WHERE storenum = 2
SELECT * FROM DB2 WHERE storenum = 3
SELECT * FROM DB2 WHERE storenum = etc.

NG,

Answer : Newbee - Is there a way to loop resultset in sqlplus script?

You are correct in your logic, you could use a parametrized CURSOR within a loop as mentioned above. You "open" the cursor and then can loop through it as needed.
1:
2:
3:
4:
5:
CURSOR c2(i_site_id IN NUMBER)
   IS
      SELECT concatenated_address
        FROM xxct_ar_addresses_v a, hz_cust_site_uses_all b
       WHERE b.site_use_id = i_site_id AND a.address_id = b.cust_acct_site_id;
Random Solutions  
 
programming4us programming4us