I am developing a procedure in pl/sql that get a data set from a cursor executed in a function. For example:
Function:
f_process_data(id_process IN NUMBER, id_product IN NUMBER)
Returns :
v_result_cursor sys_refcursor;
But the problem is that in the search of the cursor I need to send at time more than one id_product. Something like this:
id_product: 1240 (sausages) id_product: 1260 (ham)
¿How can I send (or get) more than one product in the function?
I understood that it's possible with a loop, but how?
Something like this(?):
v_sausage := 1240;
v_ham := 1260;
LOOP
IF v_count = v_sausage OR v_count = v_ham THEN
v_result_cursor := f_process_data(1, p_id_product);
END IF;
FETCH v_result_cursor
INTO v_id, v_id_product;
EXIT WHEN v_result_cursor%NOTFOUND;
END LOOP;
I expected that v_id and v_id_product has been recorded in a collection including the results from the id_product 1240 and 1260.
But, if the business rules changes and is not only 2 products, how about 100 or 1000 products?
Note: the cursor from the function it's not possible to modify, the id_product must be sent one by one.
CURSOR cu_get_value_products IS
SELECT value FROM supplies WHERE id = p_id and id_product = p_id_product;