mercredi 23 juin 2021

Alternative for IF statement in plsql select Into

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.

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.

Aucun commentaire:

Enregistrer un commentaire