dru*_*ing 1 oracle plsql plsqldeveloper
我定义了一个字符串列表,其中包含不同的国家/地区代码(如USA ,CHINA,HK,JPN等)。如何检查输入变量是否为列表中的国家/地区代码。我使用以下代码进行测试,但失败。
declare
country_list CONSTANT VARCHAR2(200) := USA,CHINA,HK,JPN;
input VARCHAR2(200);
begin
input := 'JPN';
IF input IN (country_list)
DBMS_OUTPUT.PUT_LINE('It is Inside');
else
DBMS_OUTPUT.PUT_LINE('It is not Inside');
END IF;
end;
Run Code Online (Sandbox Code Playgroud)
如果可以保证输入中不包含定界符,则可以执行以下操作:
country_list := 'USA,CHINA,HK,JPN';
input := 'JPN'; -- will be found
IF INSTR(',' || country_list || ','
,',' || input || ',') > 0 THEN
--found
ELSE
--not found
END IF;
input := 'HINA'; --will not be found
IF INSTR(',' || country_list || ','
,',' || input || ',') > 0 THEN
--found
ELSE
--not found
END IF;
Run Code Online (Sandbox Code Playgroud)