在PL/SQL里面使用if语句的时候,记得是elsif而不是elseif:
if...elsif...elsif....end if
学习案例如下:
declare
region varchar2(100) := '®ion';--声明region的字符变量且默认标签为region
country_count number := 0; --声明country_count的数值变量
begin
if upper(region) = 'EUROPE' then
select count(*) into country_count from countries where region_id = 1;
dbms_output.put_line('There are ' || country_count ||
' countries in the Europe region.');
elsif upper(region) = 'AMERICAS' then
select count(*) into country_count from countries where region_id = 2;
dbms_output.put_line('There are ' || country_count ||
' countries in the Americas region.');
elsif upper(region) = 'ASIA' then
select count(*) into country_count from countries where region_id = 3;
dbms_output.put_line('There are ' || country_count ||
' countries in the ASIA region.');
elsif upper(region) = 'MIDDLE EAST AND AFRICA' then
select count(*) into country_count from countries where region_id = 4;
dbms_output.put_line('There are ' || country_count ||
' countries in the middle East and Africa region.');
else
dbms_output.put_line('You have entered an invaid region ,please try again');
end if;
end;