3

I have some predefined values like

declare 
v_type varchar2(20);
begin
    select type into v_type from GenericTypes where id =5 ;
   // say v_type = 'XYZ'

end;

Now, i have to check if v_type is equal to 'ABC' or 'DEF' or 'ASD' and 5 more items.

so i used: if v_type = 'ABC' or v_type ='DEF' or v_type='ASD' and 5 more conditions

If there is any more efficient method to do this like using select exist etc.

2 Answers 2

3

You should be able to use the IN clause for example:

if v_type IN ('ABC','DEF','ASD') then
  do things;
end if;
Sign up to request clarification or add additional context in comments.

1 Comment

much more simple than expected. feeling like dumb
1

You could use CASE expression and check the condition in the query itself.

For example,

DECLARE
  v_type NUMBER;
BEGIN
  SELECT
    CASE
      WHEN TYPE IN ('ABC','DEF','ASD')
      THEN 1
      ELSE 0
    END GenericTypes
  INTO v_type
  WHERE ID  =5;
  IF v_type = 1 THEN
    -- do somethins
  END IF;
END;
/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.