I have a select statement like below using IF condition
If (v_block = 'apple')
then
select count(*) into v_apple_id
from table_fruits
where fruit_id = v_fruit_id;
elsif (v_block = 'mango')
then
select count(*) into v_mango_id
from table_fruits
where fruit_id = v_fruit_id;
end if;
How to Optimise this query by avoiding the IF statement.
The v_fruit_id will depend on the value in v_block. For eg. If v_block = 'Mango' then the v_fruit_id will be 1234 and if v_block = 'apple' then v_fruit_id will be 1244. and the number here like 1234 or 1244 are not the same always so the variable v_fruit_id should be given instead of hard coding the numbers
I dont want to use the IF Else statement here because there are more values for the v_block so to avoid big query with IF else i want to find an alternativ simple select statement for it.
I also need the into varibale to be according to the fruit. Incase of v_block = mango then it should be v_mango_id and in case of apple then into v_apple_id