How to use variables as an expression inside stored proc

Hi Team,

I have a string/text variable suppose var_valid_country ="‘USA’,‘UK’" I am trying to use this variable in a if condition inside stored proc like :

CREATE OR REPLACE PROCEDURE P1 ( )
AS
Declare
var_valid_country varchar(255) ="‘USA’,‘UK’,‘CANADA’,‘INDIA’"
flag varchar (10) = Null;
BEGIN

IF country IN (var_valid_country)
Then
flag = ‘Y’
else
flag = ‘N’
end if;

END ;

Although its a valid country but still its giving flag value as N.

Can anyone please assist me on this kind of scenario.

Your code is treating the whole string

“‘USA’,‘UK’,‘CANADA’,‘INDIA’”

as a single string in the IN list. Try putting all the individual strings in an array and writing a UDF “contains_string” to loop through it and return true/false if the desired string is there

Or, if you really want that condition to be in SQL, not in procedural statements in an SP, you could use dynamic SQL (executed immediate).