I have a cursor that pulls product_id and size and orders them by size asc. I'm passing a size and number(either 1 or 2) to the function. basically what I'm needing to do is return the size that is the next closest to the size I pass in. The issue becomes when I have more than 1 size available. For example, I pass a size 5, and I have products that are size 4, 4.5, 5.5, and 6. If a number 1 is also passed into the function then I just need the lowest size closest to the size passed(in this case a 4.5). If the number passed in is a 2, then I need the next closest size on THE OTHER SIDE of the item passed. For example, I would not want to pass a size 4 if I had passed 4.5 as in the example. I hope that makes sense. So If I passed a 5, and all I had was a 5.5 and a 6, when I pass the 1, it should pull 5.5, when I pass the 2, it should return null. If I passed a size 5 and had a 4.5, and a 6, then when I pass 1, i should return the 4.5, and 2 should return the 6. Here is an example of what I have so far.
function size_count(v_master_id number, v_size_no number,n)
return number is
v_no_of_records number := 0;
-- v_current_rec number := 0;
CURSOR next_size IS
select s.master_ID,s.size_no--,(v_size_no-s.size_no) size_difference
from
acntv.sku s
where s.master_id = v_master_id and
(s.size_no<=v_size_no+1 or s.size_no>=v_size_no-1) and
s.on_hand>0
order by s.size_no asc;
BEGIN
FOR rec_index IN next_size LOOP
v_no_of_records := v_no_of_records + 1;
END LOOP;
Thank you for any help you can give me.
function size_count(v_master_id number, v_size_no number,n)
return number is
v_no_of_records number := 0;
-- v_current_rec number := 0;
CURSOR next_size IS
select s.master_ID,s.size_no--,(v_size_no-s.size_no) size_difference
from
acntv.sku s
where s.master_id = v_master_id and
(s.size_no<=v_size_no+1 or s.size_no>=v_size_no-1) and
s.on_hand>0
order by s.size_no asc;
BEGIN
FOR rec_index IN next_size LOOP
v_no_of_records := v_no_of_records + 1;
END LOOP;
Thank you for any help you can give me.